在Java中查找表? [英] Lookup Tables in Java?

查看:311
本文介绍了在Java中查找表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计算机科学课程中,我们学习查找表。但是,我们的老师没有提供他所张贴的教训页面任何的例子,也没有他所提供的视频。他所做的一切是告诉我们这是什么,但他希望我们在我们的下一个任务使用它们。但他没有给我们如何做到这一点的例子。我们学习数组之前我们进入查找表。可有人


  1. 告诉我一个查找表是什么? (详情请很多?)

  2. 提供一个查找表的一些例子吗?我们应该使用数组?


解决方案

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

 地图<整数,字符串>地图=新的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

这篇关于在Java中查找表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆