Note that there are some explanatory texts on larger screens.

plurals
  1. POfind words in a hashset or treeset?
    primarykey
    data
    text
    <p>I am piping in a file and storing it into a treeset. I am trying to count unique words.. I am placing words that i dont want into a hashset. "a","the", "and"</p> <p>I want to check to see if the file contains those words, before i place them into the TreeSet.. i know i need some sort of if(word == find) ? i just dont know how to do it..</p> <p>Sorry about formatting. its hard to get it correct after you paste.</p> <p>this is what i have..</p> <pre><code>import java.util.Scanner; import java.util.ArrayList; import java.util.TreeSet; import java.util.Iterator; import java.util.HashSet; public class Project1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String word; String grab; int count = 0; int count2 =0; int count3 =0; int count4 =0; int number; TreeSet&lt;String&gt; a = new TreeSet&lt;String&gt;(); HashSet&lt;String&gt; find = new HashSet&lt;String&gt;(); System.out.println("Project 1\n"); find.add("a"); find.add("and"); find.add("the"); while (sc.hasNext()) { word = sc.next(); word = word.toLowerCase(); for(int i = 0; i &lt; word.length(); i++ ) { if(Character.isDigit(word.charAt(i))) { count3++; } } //if( a.contains("a") ) //|| word.matches("and") || word.matches("the")|| word.contains("$")) //{ // count2++; // } a.add(word); if (word.equals("---")) { break; } } System.out.println("a size"); System.out.println(a.size()); // count = count2 - count; System.out.println("unique words"); System.out.println(a.size() - count2 - count3); System.out.println("\nbye..."); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload