要想在集合中保存没有重复的元素并且按照一定的顺序排列,可以使用以下哪个集合( )
A. LinkedList
B. ArrayList
C. HashSet
D. TreeSet
查看答案
编译运行以下代码的结果是:import java.util.*;public class Test02 {public static void main(String[] args){Map music=new TreeMap();music.put(new Integer(101),"Year One");music.put(new Integer(102),"Year Two");music.put(new Integer(103),"Once upon a time");music.put(new Integer(104),null);System.out.println(music);}}
A. 程序编译时会出错,因为Integer型数据不能做为Map的键值;
B. 程序编译时会出错,因为Map对象不能将null做为值;
C. 程序编译时会出错,因为TreeMap对象不能用null做为值;
D. 程序能正确编译和运行。
编译运行以下程序的结果是:import java.util.TreeSet;public class Test02 {public static void main(String[] args) {Map map = new TreeMap(); // 创建TreeMap实例对象map.put(3, "John");map.put(2, "Tome");map.put(1, "Todd");map.put(5, "Jane");map.put(4, "William");// 新添加一个元素,sortedMap将会自动排序for (Object k : map.keySet()) {// 以for-each语句对sortedMap集合进行遍历System.out.println(k + ":" + map.get(k));}}}
A. 编译错误
B. 运行时异常
C. 1:Todd2:Tome3:John4:William5:Jane
Collections工具类中对指定List集合元素进行逆向排序的方法是
A. void reverse(List list)
B. void shuffle(List list)
C. void sort(List list)
D. void swap(List list, int i, int j)
Collections工具类中对指定List集合元素进行随机排序的方法是
A. void reverse(List list)
B. void shuffle(List list)
C. void sort(List list)
D. void swap(List list, int i, int j)