title: How to count the number of times a string appears in an array without using maps?
body: <p>I am trying to count the number of times a string appears in an array, but I cannot use any type of Map. From my research, I tried the following expecting it to work: </p>
  
  <pre><code>int count = Collections.frequency(strings, search);
  </code></pre>
  
  <p>However, when I got an error when running the program. The error was a Null Pointer Exception error and I'm not sure how to fix that or why it happened. Any ideas on whats wrong with my code?</p>
  
  <p>EDIT: Here's my full code. I can't find where the issue lies. Maybe someone else can find it 
      import java.util.*;</p>
  
  <p>public class Lab9 {</p>
  
  <pre><code> public static void main(String[] args){
       Scanner kb =  new Scanner (System.in);
       String name = null;
       List&lt;String&gt; strings =null;
       System.out.println("How many strings do you want to enter?:");
       int size = kb.nextInt();
  
       List&lt;String&gt; String = getStrings(size,name);
       System.out.println(String);
       System.out.println("What string would you like to search for?:");
       String search = kb.next();
  
       int numofTimes = countValues (search,strings);
       System.out.print("That word appears "+numofTimes+" times in the array.");
  
  
   }
   public static List&lt;String&gt; getStrings(int size,String name) {
       Scanner kb = new Scanner (System.in);
       int count = 0;
       List&lt;String&gt; strings = new ArrayList&lt;String&gt;();
       while (count != size) {
           System.out.println("Enter a string:");
           name = kb.nextLine();
           strings.add(name);
           count = count + 1;
            }
  
  return strings;
  
   }
   public static int countValues (String search, List&lt;String&gt; strings){
  
       int count = Collections.frequency(strings , search);
  
  
  
       return count;
   }
  
  
  
   }
  </code></pre>