title: Why is my method undefined for type java.lang.String
body: <p>I have a Parser class which takes in a List of strings, and prints them out line by line. I want the method <code>linecount()</code> (which does not take in any parameter) to output the number of lines in total i.e.:</p>
  
  <pre><code>import java.util.*;
  
  public class Parser{
    private static List&lt;String&gt; lines;
  
    public static String parse(List&lt;String&gt; lines){
      return String.join(System.lineSeparator(), lines); 
    }
  
    public static int linecount(){
      String newString = String.join(System.lineSeparator(), lines); 
      return (newString.split("[\r\n]")).length;
    }
  }
  </code></pre>
  
  <p>Such that when the List of string is given as: <code>List lines = Arrays.asList(new String[]{"one", "two three", ""})</code>, calling <code>Parser.parse(lines)</code> will give you </p>
  
  <pre><code>one
  two three
  
  </code></pre>
  
  <p>and thus, <code>Parser.parse(lines).linecount()</code> should output <code>3</code>. However, I came across the error <code>The method linecount() is undefined for the type java.lang.String</code>. Why is this so?</p>