当前位置 : 主页 > 编程语言 > java >

测试各个JAVA容器类

来源:互联网 收集:自由互联 发布时间:2021-06-28
测试各个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
测试各个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.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) {

		List
 
   testData = 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 + "]")); } }
                   
                  
                 
                
               
              
             
            
           
          
         
        
       
      
     
    
   
  
 
网友评论