Using a msdos window i am piping in a amazon.txt file. I am trying to use the collections framework. Keep in mind i want to keep this as simple as possible. What i want to do is count all the unique words in the file... no duplicates
This is what i have so far.. please be kind this is my first java project.
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;
public class project1
{
//ArrayList<String> a = new ArrayList<String>();
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String word;
String grab;
int count = 0;
ArrayList<String> a = new ArrayList<String>();
//Iterator<String> it = a.iterator();
System.out.println("Java project\n");
while (sc.hasNext())
{
word = sc.next();
a.add(word);
if (word.equals("---"))
{
break;
}
}
Iterator<String> it = a.iterator();
while(it.hasNext())
{
grab = it.next();
if(grab.contains("a"))
{
System.out.println(it.next()); // just a check to see
count++;
}
}
System.out.println("I counted abc = ");
System.out.println(count);
System.out.println("\nbye...");
}
}