Lookup Tables in Java?

Garrett Outlaw picture Garrett Outlaw · Feb 27, 2013 · Viewed 31.3k times · Source

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?

Answer

jlordo picture jlordo · Feb 27, 2013

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