In Java I'm using the Scanner
to read from a text file,
for example (cat, dog, mouse).
When I use the System.out.println()
the output appears like cat, dog, mouse
I want the list to look like this
cat
dog
mouse
any help code below
Scanner scan = null;
Scanner scan2 = null;
boolean same = true;
try {
scan = new Scanner(new
File("//home//mearts//keywords.txt"));
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
List<String> firstLines = new ArrayList<String>();
while (scan.hasNextLine()) {
firstLines.add(scan.nextLine());
System.out.println(firstLines);
}