
我是用C#语言的,字典的基本思路就是,键值对!每个键值对应一个值。
这一段C#代码你可以参考一下:我想对你有帮助
public class OthelloCast : List<string>
{
// Use a dictionary to contain
// cast names (key) and actor names (value)
public Dictionary<string, string> OthelloDict =
new Dictionary<string, string>();
public OthelloCast()
{
// Add data to the dictionary
OthelloDictAdd("Bianca", "Gretchen Rivas");
OthelloDictAdd("Brabantio", "Carlos Lacerda");
OthelloDictAdd("Cassio", "Steve Masters");
OthelloDictAdd("Clown", "Michael Ludwig");
OthelloDictAdd("Desdemona", "Catherine Autier Miconi");
OthelloDictAdd("Duke of Venice", "Ken Circeo");
OthelloDictAdd("Emilia", "Eva Valverde");
OthelloDictAdd("Gratiano", "Akos Kozari");
OthelloDictAdd("Iago", "Darius Stasevicius");
OthelloDictAdd("Lodovico", "Fernando Souza");
OthelloDictAdd("Montano", "Jeff Hay");
OthelloDictAdd("Othello", "Marco Tanara");
OthelloDictAdd("Roderigo", "Pedro Ruivo");
// Populate the list with character names
foreach (KeyValuePair<string, string> kvp in OthelloDict)
{
thisAdd(kvpKey);
}
}
Dictionary对象用于存储数据关键字和条目对(即类似“key=value”的形式)。它可以存取任何形式的数据的条目。每个条目都与一个唯一的关键字相关联。该关键字用来检索单个条目,通常是整数或字符串,可以是除数组外的任何类型。
下面的代码举例说明了如何创建一个 Dictionary 对象:
Dim d '创建一个变量
Set d = CreateObject(ScriptingDictionary)
dAdd "a", "Athens" '添加一些关键字和条目
dAdd "b", "Belgrade"
dAdd "c", "Cairo"
Dictionary常用的 *** 作有Add(添加)、Remove(删除)、Exists(检查某个关键字是否在字典中);常用的属性有Item(key)(获取某个关键字对应的数据),等等。
差不多就有点象平时我们在算法中提到的HashTable吧。
以上就是关于JAVA里面的dictionary<t,t>怎么用; 举个简单的例子最好,全部的内容,包括:JAVA里面的dictionary<t,t>怎么用; 举个简单的例子最好,、Java里面字典dictionary怎么定义、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)