作业

Collection 接口和 Collections 类都是做什么用的 ?

Collection是集合类的顶级接口。它提供对集合对象进行基本操作的通用接口方法。它的直接继承接口有List,Set和Queue.
Collections是一个包装类。此类完全由在 collection 上进行操作或返回 collection 的静态方法组成。它不能被实例化,起到一个工具类的作用

Collection 接口有几个子接口 ?Map 接口有父接口么 ?

三个子接口,List Set Queue 没有

List 、 Set 、 Map 三个接口有什么特点 ?

List接口继承Collection接口,称为有序集合,允许有重复的元素。

Set接口常用类有HashSet和TreeSet,HashSet储存顺序为无序,TreeSet储存顺序为有序不允许元素的重复。

Map接口用来处理建-值映射数据的储存,可以储存多个元素。
请简述哈希表(散列表)

根据关键码值而直接进行访问得数据结构,通过把关键码值映射到表中的一个位置来访问记录,以加快查找的速度。

以下哪个集合接口支持通过字符串主键检索对象 A

A.Map

B.Set

C.List

D.Collection

以下哪些语句用于创建一个Map实例?D

A.Map m = new Map();

B.Map m = new Map(init capacity,increment capacity);

C.Map m = new Map(new Collection());

D.以上均不行

以下代码的执行结果是?

public class Example {

public static void main(String[] args) {

 String s1 = "abc";
 String s2 = "def";
 String s3 = "def";

 List<String> list = new ArrayList<String>();
 list.add(s1);
 list.add(s2);
 list.add(s3);
 
 for (String string : list) {
     System.out.println( string );
 }
 
 System.out.println("-------------------");
 
 Set<String> set = new HashSet<>();
 set.add(s1);
 set.add(s2);
 set.add(s3);
 
 for (String string : set) {
     System.out.println( string );
 }

}
}
执行结果 abc def def abc def

以下代码执行结果是?TreeMap和 HashMap 的区别是什么 ?

执行结果one =1 three = 3 two = 2 TreeMap 是有序的 HashMap是无序的**

public class Example {

public static void main(String[] args) {

 TreeMap<String, String> map = new TreeMap<String, String>();
 map.put("one", "1");
 map.put("two", "2");
 map.put("three", "3");
 displayMap(map);

}

static void displayMap(TreeMap map) {

 Collection<String> c = map.entrySet();
 Iterator<String> i = c.iterator();

 while (i.hasNext()) {
     Object o = i.next();
     System.out.print(o.toString());
 }

}
}
Vector、ArrayList 和 LinkedList 有什么区别 ?

ector是线程安全,性能比ArrayList要差 ArrayList重速度,轻安全,是线程的非安全,需要程序员自己管理线程的同步问题 .Vector和ArrayList有利于节约空间
LinkedList是link的双向数据列表,可当作堆栈、队列、双端队列。链表是一种在物理上非连续、非顺序的数据结构,由若干节点node所组成

Arrays.ArrayList 和 java.util.ArrayList 有什么区别 ?

ArrayList是List接口实现类
Arrays.ArrayList 没有add()方法的,修改元素是通过之前传过来的数组进行修改

Hashtable和HashMap的区别

1 Hashtable继承自Dictionary类 ,而HashMap实现了Map接口
2 Hashtable的方法是同步的,而HashMap的方法不是,消耗一定度资源要增加一些步骤控制增加了处理过程,Hashtable不允许null值(Key和Value都不允许)。

分别使用 HashMap 和 List 以及数组统计数组中相同的值出现的次数

两次

String[] array = {"abc" , "ABC" , "123" , "def" , "_" , "def" , "abc"};
请写出 Iterator 迭代器的优点

java迭代器查找的唯一操作就是依靠调用next,而在执行查找任务的同时,迭代器的位置也在改变.
Iterator迭代器remove方法会删除上次调用next方法返回的元素.这也意味之remove方法和next有着很强的依赖性.如果在 调用remove之前没有调用next是不合法的 .这个接口衍生出了,java集合的迭代器.java集合的迭代器使用

请写出循环 List 、Set、Map 的代码

for( 集合元素类型 i : list ) {

 System.out.println(i)

 }  

  for( 集合元素类型  i : Set ) {

  System.out.println(i)

 }  
 for (Map.Entry<String,String> m : map01.entrySet()) {
System.out.println(m);

}

以下哪个集合接口支持元素排序 A

A.Collection

B.Set

C.List

D.Map

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Collection 接口和 Collections 类都是做什么用的 ?Collection接口和Collect...
    朱梦轩阅读 436评论 0 0
  • 1. Collection 接口和 Collections 类都是做什么用的 ? **Collection:集...
    杜卫东阅读 325评论 0 0
  • Collection 接口和 Collections 类都是做什么用的 ?Collection:集合的抽象数据类型...
    开心_1acc阅读 152评论 0 0
  • Collection 接口和 Collections 类都是做什么用的 ? Collection:集合的抽象数据类...
    eeb9d901fda2阅读 193评论 0 0
  • Collection 接口和 Collections 类都是做什么用的 ?Collection:集合的抽象数据类型...
    常皓钦阅读 263评论 0 0

友情链接更多精彩内容