List collection of duplicate data query, the query repetitions

Package com.cfam.controller; 

Import of java.util.ArrayList;
 Import the java.util.HashMap;
 Import java.util.List;
 Import a java.util.Map;
 Import java.util.Random; 

/ ** 
 * <P> 
 * the Title: ListToRepeat.java </ the p-> 
 * <the p-> 
 * the Description: List query complex data collection, query the number of repetitions </ the p-> 
 * 
 * @author ken chen 
 * @date 2019 Nian 8 Yue 5 Ri 
 * @version 1.0
  * / 
public  class ListToRepeat { 

    public  static  void main (String [] args) { 

        List <String> Lists =new new the ArrayList <String> (); 

        for ( int I = 0; I <10; I ++ ) {
             // add a random number 
            lists.add (String.valueOf ( new new the Random () the nextInt (. 8. ))); 

        } 
        // creating a collection Map 
        Map <String, Integer> = map new new the HashMap <String, Integer> (); 

        for (String List: Lists) {
             // create a counter to increment 
            Integer = I. 1 ;
             // If the map set to take the added value list accessible to the counter value is assigned to mapkey mapvalue + 1'd; 
            IF (! as map.get (list) = null ) {
                 //Increment a counter 
                I = as map.get (list) + 1 ; 
            } 
            // Map Update value plus 1 is repeated without repeating assigned to Map 
            map.put (list, I); 
        } 
        // value is set number list appears 
        System .out.println ( "map data is" + map.toString ()); 

        // iterate map set 
        for (S String: map.keySet ()) {
             // the number of inquiries occurring value 
            IF (as map.get (S )> 1 ) {
                 // print counter data occurs one or more times 
                System.out.print (s + "" + "number of occurrences" + map.get (s) + "views" ); 
            } 
        } 

    } 
}

 

Guess you like

Origin www.cnblogs.com/qqqq122418812/p/11301720.html