Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are many ways you can do this, let me explain to you a way that is both efficient and easy to understand .. and of course OO.</p> <p>[Step 1] You gotta have two maps one that stores file specific data and the other that stores filename and that files data. Instead of filename you can choose whatever you want.</p> <pre><code>private static HashMap&lt;String, MutableInt&gt; wordMap1 = new HashMap&lt;String, MutableInt&gt;(); private static HashMap&lt;String, MutableInt&gt; wordMap2 = new HashMap&lt;String, MutableInt&gt;(); private static HashMap&lt;String, HashMap&gt; fileMap = new HashMap&lt;String, HashMap&gt;(); </code></pre> <p>[Step 2] Make the MutableInt class (technically you wanna do this first) Now you might ask what is the MutableInt, its a class that you will create so that you can increment the value for a given word as you encounter it.</p> <p>Here is an example of the MutableInt class:</p> <pre><code>class MutableInt { int value = 1; public void increase () { ++value; } public int getValue () { return value; } public String toString(){ return Integer.toString(value); } } </code></pre> <p>[Step 3] Now for each word in the given file do the following:</p> <ol> <li>create a new wordMap for file you are parsing</li> <li>get the word from file</li> <li>check if word is in wordMap using wordmap.get("word");</li> <li>if output is null then you know its a new word.</li> <li>put the word in the map and put a MutableInt in its value using </li> <li>wordmap.put('word", new MutableInt());</li> <li>if output is not null then you know there it is not a new word so increase the counter using wordMap.getValue("word).increase();</li> <li>Once you are done doing this with all the words in the file you want to put the wordMap in the fileMap using fileMap.put("filename",wordMap);</li> </ol>
    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.
    1. VO
      singulars
      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