07..集合

来源:互联网 发布:战网网络问题 编辑:程序博客网 时间:2024/05/16 19:12

集合框架接口的分类:Collection接口 和 Map接口

List接口和Set接口继承Collection接口

SortedSet接口继承Set接口、SortedMap接口继承Map接口

List接口实现类:ArrayList、LinkedList

代码:

public class TestCollection {

 

 public static voidmain(String[] args)

 {

  TestQueue();

  TestMap();

 }

 

 //队列

 public static voidTestQueue()

 {

 Queue<String> queue = new LinkedList<String>();

 queue.offer("a");

 queue.offer("b");

 System.out.println(queue.poll());

 queue.offer("c");

 System.out.println(queue.poll());

 System.out.println(queue.poll());

 }

 // Map

 public static voidTestMap()

 {

 TreeMap<String,String> map = new TreeMap<String,String>();

 map.put("2", "a");

 map.put("1", "a");

 System.out.println(map.firstKey());

 }

}

0 0