title: method to return hashmap from text
body: <p>I am trying to write a method that takes an InputStream variable and returns a HashMap back to main. However I'm stuck on how to return the variable of HashMap. New to Java so I do not know what I'm doing wrong.For the return statement: pairsCount cannot be resolved to variable. Thanks in advance.</p>
  
  <pre><code>private static Map&lt;String, Integer&gt; getHashMap(InputStream in)
  { 
  
      if (in != null) 
      {
          // Using a Scanner object to read one word at a time from the input stream.
          @SuppressWarnings("resource")
          Scanner sc = new Scanner(in);   
          String word;
          System.out.println(" - Assignment 1 -s%n%n\n");
          // Continue getting words until we reach the end of input 
          List&lt;String&gt; inputWords = new ArrayList&lt;String&gt;();
  
          while (sc.hasNext()) 
          {  
              word = sc.next();       
              if (!word.equals(null)) 
              {
                  inputWords.add(word);
              }
          }
          Map&lt;String, Integer&gt; pairsCount = new HashMap&lt;&gt;();
          Iterator&lt;String&gt; it = inputWords.iterator();
  
          String currentWord = null;
          String previousWord = null;
  
          Integer wordCount = 0;
          while(it.hasNext())
          {
              currentWord = it.next();
              if( previousWord != null ) 
              {
                  String key = previousWord.concat( "#" ).concat( currentWord );
              if( pairsCount.containsKey( key ) ) 
              {
                Integer lastCount = pairsCount.get( key );
                pairsCount.put( key, lastCount + 1 );
                wordCount = wordCount + lastCount;
              } 
              else 
              {
                pairsCount.put( key, 1 );
                wordCount =  1;
              }
           }
              previousWord = currentWord;     
  
       }
  
      }
      return (pairsCount);
  
  }
  </code></pre>