EDITED:
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
public class y {
Set<String> setA = new HashSet<String>();
Set<String> getSetA(BufferedReader br) throws IOException {
String line;
while ((line = br.readLine()) != null) {
setA.add(line);
}
br.close();
Iterator<String> iter = setA.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
return setA;
}
}
I try to read every line of a file into element of the Set. But it seem like only the n line is added into the Set. The println only print out the n line in the whole text what wrong with my code?
replace your if with a while.
and then later