Method One, use the For loop traversal to remove the repeating element code in the list as follows
Public Static voidMain (string[] args) {Test07 test07=NewTest07 (); System.out.println (Test07.getlist ()); } PublicList getList () {list originallist=NewArrayList (); Originallist.add (1); Originallist.add (3); Originallist.add (3); Originallist.add (5); Originallist.add (7); Originallist.add (7); Originallist.add (13); List templist=NewArrayList (); for(Object object:originallist) {if(!Templist.contains (object)) {Templist.add (object); } } returntemplist; }
Mode two, use set to redo the code snippet as follows
// The use of set set uniqueness to remove weight New HashSet (originallist); New ArrayList (set); return templist;
Method three, using TreeSet to remove duplicate elements
New TreeSet (originallist); New ArrayList (); Templist.addall (TreeSet); return templist;
Java implementation of the list to go heavy