Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating and printing HashMap<String, Integer>
    primarykey
    data
    text
    <pre><code>import java.util.*; import java.lang.Iterable; public class WordGroup { String words; public static void main(String[] args) { WordGroup plato = new WordGroup( "You can discover more about a person in an hour of play than in a year of conversation"); WordGroup roosevelt = new WordGroup( "When you play play hard when you work dont play at all"); String[] platoArray = plato.getWordArray(); String[] rooseveltArray = roosevelt.getWordArray(); plato.printArray(platoArray); roosevelt.printArray(rooseveltArray); System.out.println("____________________________________________________"); HashSet&lt;String&gt; rooseveltWordSet = roosevelt.getWordSet(platoArray); roosevelt.printArray(rooseveltWordSet); } public WordGroup(String word) { words = word.toLowerCase(); } protected String[] getWordArray() { String[] wordArray = words.split(" "); return wordArray; } protected HashSet&lt;String&gt; getWordSet(String[] groupedWords) { HashSet&lt;String&gt; wordSet = new HashSet&lt;String&gt;(); for (String string : groupedWords) { wordSet.add(string); } String[] wordArray = getWordArray(); for (String string : wordArray) { wordSet.add(string); } return wordSet; } protected void printArray(String[] array) { for (String string : array) { System.out.println(string); } } protected void printArray(HashSet&lt;String&gt; hashWords) { for(String hashset: hashWords) { System.out.println(hashset); } } protected void printArray(HashMap&lt;String, Integer&gt; printHashMap) { for(String string: printHashMap) { System.out.println(string); } } protected HashMap&lt;String, Integer&gt; getWordCounts() { String[] wordArray = getWordArray(); HashMap&lt;String, Integer&gt; wordCounts = new HashMap&lt;String, Integer&gt;(); for(String string: wordArray) { int one = 1; wordCounts.put(string, +one); } return null; } } </code></pre> <p>Im trying to make getWordCounts() to make a hashmap that contains the words used in two strings and remembering the word and the amount of times that word is used. printArray(HashMap printHashMap) is ment to Iterate through the HashMap created in getWordCounts() and print out the data.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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