Private Static voidcheck (string[] array) {//what are the string arrays that contain non-repeating strings? The number of each repetitionmap<string,integer> Map = new hashmap<> (); for (int i=0;i<array.length;i++) {if (Map.get (array[i]) = null) {Map.put (Array[i], Map.get ( Array[i]) + 1);//value + 1} else {map.put (array[i],1); } } //① Traversal MapSystem.out.println ("Traverse key and Value by Map.keyset ():"); for(String key:map.keySet ()) {System.out.println ("The array is:" + key + "=" +Map.get (key)); } //②mapset (). Iterator ()SYSTEM.OUT.PRINTLN ("Traversal of key and value through Map.entryset () iterator ()"); Iterator<entry<string, integer>> it =Map.entryset (). iterator (); while(It.hasnext ()) {Entry<string, integer> entry =It.next (); System.out.println ("The array is:" + entry.getkey () + "=" +Entry.getvalue ()); } //③mapset () recommended when capacity is largeSystem.out.println ("Traverse key and value through Map.entryset ()"); for(Entry<string, integer>Entry:map.entrySet ()) {System.out.println ("The array is:" + entry.getkey () + "=" +Entry.getvalue ()); } //④System.out.println ("Traverse all value through Map.values (), but cannot traverse key"); for(Integer value:map.values ()) {System.out.println ("= " +value); } }
Array deduplication and record repetition (and four ways to traverse the map)