title: In Java, using Scanner, Is there a way to find a specific String in a CSV file, use it as a column header and return all values under it?
body: <p>I am trying to find the String "5464" in a csv document then have it return all of the values under that String (same number of Delimiters from the start of the line), until reaching the end of the list (no more values in the column). Any help would be sincerely appreciated.</p>
  
  <pre><code>import javax.swing.JOptionPane;
  public class SearchNdestroyV2 {
  
  
      private static Scanner x;
  
  
      public static void main(String[] args)  {
          String filepath = "tutorial.txt";
          String searchTerm = "5464"
  
          readRecord(searchTerm,filepath);
      }
  
      public void readRecord(String searchTerm, String filepath)
      {
          boolean found = false;
          String ID = ""; String ID2 = ""; String ID3 = "";
  
      }
          try 
          {
              x = new Scanner(new File(filepath));
              x.useDelimeter("[,\n]");
  
              while(x.hasNext() &amp;&amp; !found )
              {
                  ID = x.next();
                  ID2 = x.nextLine();
                  ID3 = x.nextLine();
  
                  if(ID.equals(searchTerm))
                  {
                      found = true;
                  }
  
              }
  
              if (found)
              {
                  JOptionPane.showMessageDialog(null,"ID: " + ID + "ID2: " + ID2 + "ID3: "+ID3);
              }
          }   
              else
              {
                  JOptionPane.showMessageDialog(null, "Error:");
              }
          catch(Exception e)
          {
  
          }
      {  
  }
  
  </code></pre>