浙江建设培训中心网站,网站建设宣传方案,企业网站建设457,北京建设注册中心网站有序列允许元素重复否Collection否是List是是SetAbstractSet否 否HashSetTreeSet是#xff08;用二叉树排序#xff09;MapAbstractMap否 使用key-value来映射和存储数据#xff0c; Key必须惟一#xff0c;value可以重复 HashMapTreeMap是#xff08;用二叉树… 有序列允许元素重复否Collection否是List是是SetAbstractSet否 否HashSetTreeSet是用二叉树排序MapAbstractMap否 使用key-value来映射和存储数据 Key必须惟一value可以重复 HashMapTreeMap是用二叉树排序 几个面试常见问题1.Q:ArrayList和Vector有什么区别HashMap和HashTable有什么区别A:Vector和HashTable是线程同步的synchronized。性能上ArrayList和HashMap分别比Vector和Hashtable要好。2.Q:大致讲解java集合的体系结构A:List、Set、Map是这个集合体系中最主要的三个接口。其中List和Set继承自Collection接口。Set不允许元素重复。HashSet和TreeSet是两个主要的实现类。List有序且允许元素重复。ArrayList、LinkedList和Vector是三个主要的实现类。Map也属于集合系统但和Collection接口不同。Map是key对value的映射集合其中key列就是一个集合。key不能重复但是value可以重复。HashMap、TreeMap和Hashtable是三个主要的实现类。SortedSet和SortedMap接口对元素按指定规则排序SortedMap是对key列进行排序。3.QComparable和Comparator区别A:调用java.util.Collections.sort(List list)方法来进行排序的时候List内的Object都必须实现了Comparable接口。java.util.Collections.sort(List listComparator c)可以临时声明一个Comparator 来实现排序。Collections.sort(imageList, new Comparator() {public int compare(Object a, Object b) {int orderA Integer.parseInt( ( (Image) a).getSequence());int orderB Integer.parseInt( ( (Image) b).getSequence());return orderA - orderB;}});如果需要改变排列顺序改成return orderb - orderA 即可。4.Q:简述equals()和hashCode()A:...不知道。下回分解public interfaceCollectionextends Iterablepublic interfaceListextends Collectionpublic abstract classAbstractListextends AbstractCollectionimplements Listpublic classVectorextends AbstractListimplements List,RandomAccess,java.lang.Cloneable,java.io.Serializable基于Array是“sychronized”的public classArrayListextends AbstractListimplements List,RandomAccess,Cloneable,java.io.Serializable基于ArrayArrayList是非同步的。所以在性能上要比Vector优越一些public classLinkedListextends AbstractSequentialListimplements List,Queue,Cloneable,java.io.Serializable不基于Array基于Array的ListVectorArrayList适合查询而LinkedList链表适合添加删除操作List基本上都是以Array为基础。但是Set则是在HashMap的基础上来实现的这个就是Set和List的根本区别public abstract class AbstractSetextends AbstractCollectionimplements Setpublic class HashSetextends AbstractSetimplements Set, Cloneable, java.io.SerializableHashSet的存储方式是把HashMap中的Key作为Set的对应存储项public class LinkedHashSetextends HashSetimplements Set, Cloneable, java.io.Serializablepublic class TreeSetextends AbstractSetimplements SortedSet, Cloneable, java.io.Serializable它是通过SortedMap来实现的public interface MapK,Vpublic abstract class AbstractMapK,Vimplements MapK,Vpublic class HashMapK,Vextends AbstractMapK,Vimplements MapK,V, Cloneable, Serializablepublic class TreeMapK,Vextends AbstractMapK,Vimplements SortedMapK,V, Cloneable, java.io.SerializableHashMap通过hashcode对其内容进行快速查找而TreeMap中所有的元素都保持着某种固定的顺序如果你需要得到一个有序的结果你就应该使用TreeMapHashMap中元素的排列顺序是不固定的 转载于:https://www.cnblogs.com/haitang/p/4769311.html