ArrayList can only use the Contains method to judge all objects that are read into memory at once, thus removing duplicates.
list<string> seqId = new arraylist<string> (); for (int i = 0; i < alllines.length; i++) {string[ ] Eachline = Alllines[i].split ("[\ t]"); System.out.println (Eachline[0]); if (!seqid.contains (eachline[0))) {Seqid.add (eachline[0]); }}
HashSet can remove repetition;
And to specify the object type,
hashset<string> seqidset = new hashset<string> ();iterator<string> IdS = Seqidset.iterator (); while ( Ids.hasnext ()) {String tmpid = Ids.next (); string tmp = new string (tmpid); String Eachidinset = tmp.substring (0,tmp.indexof (".")); System.out.println ("..." +eachidinset); System.out.println (Eachidinset);}
And iterator can only generate one iteration object and cannot be reused.
iterator<string> IdS = Seqidset.iterator (); This sentence if you do not specify a <String> object of this type, the following String tmpid = Ids.next (); will be changed to Object tmpid = Ids.next ();
The Java classes you need to import are as follows:
/** import java.io.file;import java.io.fileinputstream;import java.io.filereader;import Java.io.IOException;import Java.io.bufferedreader;import Java.util.Scanner; */import java.util.iterator;import java.util.hashmap;import Java.util.set;import java.util.HashSet;import Java.util.arraylist;import java.util.List;
This article is from the "R Language Learning history" blog, please be sure to keep this source http://matrix6ro.blog.51cto.com/1746429/1773312
Java's ArrayList cannot be duplicated, using HashSet