2つの文字列配列aとbがあり、同じ要素(a、bともに大きい)を探しています.

2829 ワード

import java.util.*;
import java.util.logging.Logger;

public class Main {   
    private Logger logger = Logger.getLogger("ss");   
    public static void main(String[] args){
    	Main m = new Main();
    	m.getSameElementByList();
    	m.getSameElementByMap();
    }
    //  :  =  2-( 2- 1 = )   
    public void getSameElementByList() {   
        Long begin=System.currentTimeMillis();   
        String[] strArr1 = { "xiaoxin", "niutou", "shanqiu", "luobo"};   
        String[] strArr2 = { "xiaoxin", "ggg", "shanqiu", "meile", "dddsf", "niutou" };   
        List<String> coll = Arrays.asList(strArr1);   
        List<String> coll2 = Arrays.asList(strArr2);   
        List<String> alter0 = new ArrayList<String>(coll2);   
        List<String> alter1 = new ArrayList<String>(coll);   
        List<String> alter2 = new ArrayList<String>(coll2);   
        alter2.removeAll(alter1);   
        Iterator<String> it1 = alter2.iterator();   
        while (it1.hasNext())   
            logger.info(it1.next());   
        logger.info("------- -----------");   
        alter0.removeAll(alter2);   
        Iterator<String> it2 = alter0.iterator();   
        while (it2.hasNext())   
        {   
            logger.info(it2.next());   
        }   
        Long end=System.currentTimeMillis();   
        logger.info(String.valueOf(end-begin));   
    }   
    /**  
     *  A map key, value, B , NULL,   
     */  
    public void getSameElementByMap(){   
        Long begin=System.currentTimeMillis();   
        logger.info("------- -----------");   
        String[] strArr1 = { "xiaoxin", "niutou", "shanqiu", "luobo" };   
        String[] strArr2 = { "xiaoxin", "ggg", "shanqiu", "meile", "dddsf", "niutou" };   
        HashMap<String,Object> map=new HashMap<String, Object>();   
        for (String string1 : strArr1) {   
            map.put(string1, string1);   
        }   
        for (String string2 : strArr2) {   
            Object j=map.get(string2);   
            if(j!=null){   
                logger.info(j.toString());   
            }   
        }   
        Long end=System.currentTimeMillis();   
        logger.info(String.valueOf(end-begin));   
           
    }   
}// 。 ,   
フォーラムからこの招待状の討論を見て、とても良いです...ここに記録する