非泛型集合ArrayList和HashTable
2015-03-15 12:28
169 查看
今天看一下ArrayList和HashTable。ArrayLis的使用非常简单,首先得手动Using一个库System.collection ,哈希表也同样得引入该库。
首先定义非泛型集合ArrayList,
删除则调用removed方法就可以了。ArrayList可以自动加入新对象而不用事先定义空间大小,其间的代码也应该非常简单,应该类似与c的malloc(sizeof(stu1));之类的。
然而访问ArrayList需要使用索引访问,如果数据过多,变化很大的话则非常难以跟踪对象的索引值,所以在ArrayList上添加了HashTable,使用函数传递的key来检索对应位置,然后可以方便的操作对应的对象。
HashTable更像是给对象取了一个别名,通过这个别名来找到对象,而不用理会其索引。
哈希表的遍历不同于arrayList,哈希表遍历可以遍历其至或者其key
首先定义非泛型集合ArrayList,
ArrayList List = new ArrayList();
</pre>然后加入对象<pre name="code" class="csharp">list.add(stu1); list.add(stu2);
删除则调用removed方法就可以了。ArrayList可以自动加入新对象而不用事先定义空间大小,其间的代码也应该非常简单,应该类似与c的malloc(sizeof(stu1));之类的。
然而访问ArrayList需要使用索引访问,如果数据过多,变化很大的话则非常难以跟踪对象的索引值,所以在ArrayList上添加了HashTable,使用函数传递的key来检索对应位置,然后可以方便的操作对应的对象。
HashTable更像是给对象取了一个别名,通过这个别名来找到对象,而不用理会其索引。
HashTable list = nwe lHashTable(); list.add("key1",stu1); list.add("key2", stu2); list["key1"];
list.remove("key1");<pre name="code" class="html">student obj = (student) list["key2"]
哈希表的遍历不同于arrayList,哈希表遍历可以遍历其至或者其key
foreach(<span style="color:#3333ff;">string</span> key in list.keys)
{
</pre><pre name="code" class="html">}
//or
foreach(<span style="color:#ff0000;">object</span> <span style="color:#ff0000;">item</span> in list.value)
{
</pre><pre name="code" class="html">}
相关文章推荐
- 2012.6.4 ArrayList集合 List泛型 Hashtable键值对的集合 Dictionary
- 集合ArrayList Hashtable,泛型集合
- 集合(ArrayList、Hashtable、泛型集合)
- 黑马程序员_学习日记39_604基础加强(垃圾回收、弱引用、集合ArrayList和Hashtable、泛型集合List和Dictionary、var)
- [C#]泛型与非泛型集合类的区别及使用例程,包括ArrayList,Hashtable,List<T>,Dictionary<Tkey,Tvalue>,SortedList<Tkey,Tvalue>,Queue<T>,Stack<T>等
- C#集合类(HashTable, Dictionary, ArrayList)与HashTable
- C#基础(18)——List泛型集合、装箱、拆箱、字典集合与Hashtable区别
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(HashTable, Dictionary, ArrayList)与HashTable线程安全
- C# 泛型集合List和非泛型集合ArrayList的性能比较
- java集合(ArrayList、vector、HashMap、HashTable)源码剖析
- 数组/集合(ArrayList)/泛型
- C#ArrayList 集合 和list<t>泛型集合
- java集合--ArrayList HashSet HashMap Hashtable LinkList
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
- 针对ArrayList集合3种遍历方法的总结,加入jdk5新特性之一泛型,同时加入jdk8新特性的使用
- C# 泛型集合List和非泛型集合ArrayList的性能比较
- 具体的集合类(一)ArrayList,LinkedList,Vector,HashMap,HashTable
- 各种集合小结:arrayList和linkedList,Vector;hashmap和hashtable,hashset,
- C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)