且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Java中查找表?

更新时间:2023-02-26 14:49:14

您可以使用地图存储键/值对查找和值由它的键:

 地图<整数,字符串>地图=新的HashMap<>();
map.put(1,富);
map.put(2,酒吧);
的System.out.println(map.get(1)); //输出美孚

In my Computer Science course, we're learning about Lookup Tables. But our teacher did not provide any examples in the lesson pages he has posted, nor the videos he provided. All he did was tell us what it was but he wants us to use them in our next assignment. But he has failed to give us examples of how to do it. We were learning about Arrays before we got into Lookup Tables. Can someone

  1. Tell me what a Lookup Table is? (Lots of details please?)
  2. Provide some examples of a Lookup Table? We're supposed to use Arrays?

You can use a map to store key/value pairs and lookup a value by it's key:

Map<Integer, String> map = new HashMap<>();
map.put(1, "Foo");
map.put(2, "Bar");
System.out.println(map.get(1)); // prints Foo