Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't see why you'd need an array of hashsets. Here's what I invision:</p> <pre><code>Set&lt;String&gt; dictionary = new HashSet&lt;String&gt;(); dictionary.add("One"); dictionary.add("Two"); dictionary.add("Three"); dictionary.add("Four"); </code></pre> <p>And here is how I would use it. Note: don't read below unless you want an actual answer to the breaking-into-words problem. It may diminish how much learning you get. So only read it if you're okay with it being spoiled.</p> <pre><code>List&lt;String&gt; split(String sentence) { List&lt;String&gt; words = new LinkedList&lt;String&gt;(); String word = ""; // StringBuilder actually is not orders faster in // this case or I would advocate using it... for(int i = 0; i &lt; sentence.length(); i++) { word += sentence.charAt(i); // creates a new String anyway, so StringBuilder // is far less powerful if(dictionary.contains(word) { words.add(word); word = ""; } } return words; } </code></pre> <p>Some concerns:</p> <p>Let us assume your sentences and words are all in lowercase, to avoid case sensitivity. Let us also assume your dictionary contains every common English word.</p> <pre><code>dictionary.add("this"); dictionary.add("is"); dictionary.add("a"); dictionary.add("test"); </code></pre> <p>And run "thisisatest" and it will split it properly.</p> <p>Now, keep in mind there are other words.</p> <pre><code>dictionary.add("i"); dictionary.add("sat"); dictionary.add("est"); </code></pre> <p>These are all valid words. Running it will give you</p> <pre><code>"this" "i" "sat" "est" </code></pre> <p>In fact, by this logic, EVERY word that starts with <code>i</code> or <code>a</code> will end up getting missed. And that's bad. Especially for words like <code>"apple"</code> You will get <code>a</code> as the first word, then continue searching for <code>"pple"</code> and words that start with <code>"pple"</code>. That's going to cause a lot of problems!</p> <p>Even if you can get around this problem, you're going to run into problems where the words are always valid.</p> <p>Consider "thetreescare". Is it "the" "tree" "scare" or "the" "trees" "care". You are unable to make the differentiation - ever!</p> <p>So the problem you have picked is a dousie, for sure!</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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