linkedlist collection deduplication

/ ** 
* number of known storage array QQ number, QQ number up to 11, a minimum of 5
* String [] strs = { " 12345", "67891", "12347809933", "98765432102", "67891 "" 12347809933 "}.
* All inside the array qq number are stored in the LinkedList, remove the duplicate list element,
* the list of all the elements are printed out and enhanced by an iterative loop for
* /
public class LinkedList02 {
public static void main (String [] args) {
the linkedList <String> linkedList = new new the linkedList <> ();
String [] STRs = { "12345", "67891", "12,347,809,933", "98,765,432,102", "67891", "12,347,809,933"};
for (int I = 0; I <strs.length; I ++) {
String STRs STR = [I];
linkedList.add (STR);




Remove duplicate using an iterator element, can maintain the original order of
* /
the Iterator <String> = linkedList.iterator Iterator ();
the LinkedList <String> = new new newlist1 the LinkedList <> ();
the while (iterator.hasNext ()) {
String Next Iterator.next = ();
// add a new element is not set to a new set of
IF {(newlist1.contains (Next)!)
newlist1.add (Next);
}
}
System.out.println (newlist1);
the System .out.println ( "------------ ------------- method II");

/ *
use HashSet without repetition characteristics, but after the deduplication List can not maintain the original order
* /
// S hashset remove duplicate using
Set <String> set = new HashSet <> (linkedList);
// get a new set of de-duplicated
the LinkedList <String> = new new newList the LinkedList <> (SET);
System.out.println (newList);


}
}

Guess you like

Origin www.cnblogs.com/YRSWBY2016/p/12018524.html