测试各个JAVA容器类 package org.weisiqian.test;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.LinkedHashSet;import java.util.LinkedLis
package org.weisiqian.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; public class Test { public static void main(String[] args) { ListtestData = Arrays.asList(1, 3, 2, 10, 9, 8); System.out.println("max:" + Collections.max(testData)); System.out.println("min:" + Collections.min(testData)); System.out.println(); // List System.out.print("ArrayList:"); List arrayList = new ArrayList (testData); arrayList.forEach(element -> System.out.print(element + " ")); System.out.println(); System.out.print("LinkedList:"); List linkedList = new LinkedList (testData); linkedList.forEach(element -> System.out.print(element + " ")); System.out.println(); System.out.print("Vector:"); List vector = new Vector (testData); vector.forEach(element -> System.out.print(element + " ")); System.out.println(); System.out.print("Stack:"); List stack = new Stack (); stack.addAll(testData); stack.forEach(element -> System.out.print(element + " ")); System.out.println(); // Set System.out.print("\nTreeSet:"); Set treeSet = new TreeSet (testData); treeSet.forEach(element -> System.out.print(element + " ")); System.out.println(); System.out.print("HashSet:"); Set hashSet = new HashSet (testData); hashSet.forEach(element -> System.out.print(element + " ")); System.out.println(); System.out.print("LinkedHashSet:"); Set linkedHashSet = new LinkedHashSet (testData); linkedHashSet.forEach(element -> System.out.print(element + " ")); System.out.println(); // Map System.out.println("\nHashMap:"); Map hashMap = new HashMap (); testData.forEach(element -> hashMap.put(element, element)); hashMap.forEach((key, value) -> System.out.println("[" + key + "," + value + "]")); System.out.println("TreeMap:"); Map treeMap = new TreeMap (); testData.forEach(element -> treeMap.put(element, element)); treeMap.forEach((key, value) -> System.out.println("[" + key + "," + value + "]")); } }