title: Java: Parsing Input separated by commas
body: <p>Java program:</p>
  
  <p>The input below is just off the top of my head. What I'm looking for is how to take specific portions of input data based on whether they are a string or a primitive type... and here I'm thinking it might be useful to use the comma that separates them somehow.  </p>
  
  <pre><code>   /* Given input:
     *
     * Massachusetts, Ma, Boston, 10000, 20000
     * California, CA, Los Angeles, 30000, 40000
  
     * How would you print:
  
     * Massachusetts    20000
     * California       40000
     */
  
  public static void main(String[] args) {
       Scanner userInput = new Scanner(System.in) ;
  
       while (userInput.hasNextLine()) {
           String state = userInput.nextLine() ;
           Double population = userInput.nextDouble() ;
           String temp = userInput.nextLine() ; // for the new line
  
           System.out.printf( "%s %2f" , state , population ) ;
       }
  }
  </code></pre>
  
  <p>Also I've seen a method called useDelimiter(), I was wondering if that might help break up the input from my Scanner.</p>