title: importing a csv file into a java swing table
body: <p>I have a csv file of all the stock quotes on in the nyse. first column is symbol second column is the name of the company.</p>
  
  <p>I have a search box and table made in netbeans using the java swing library.</p>
  
  <p>Right now when I enter the name in the box it is returning the correct amount of rows. So for instance if I search GOOG it will only return 2 rows (1 row for the GOOG symbol and one row for the name in the full company name). However the data within the rows is not the correct ones it is just printing the first row of the csv file over and over. here is the code that gets executed when clicking the search button:</p>
  
  <pre><code>package my.Stock;
  
  
  import java.util.ArrayList;
  import java.util.Scanner;
  import java.io.BufferedReader;
  import java.util.StringTokenizer;
  import java.io.FileReader;
  import java.io.*;
  
  public class searchy {
  
      public static void doSearch(String s){
  
  
                                    javax.swing.JTable resTable = StockUI.stockUI.getResultTable();
                                    javax.swing.table.DefaultTableModel dtm =
                                            (javax.swing.table.DefaultTableModel) resTable.getModel();
  
                                    while (dtm.getRowCount()&gt; 0 ) dtm.removeRow(0);
  
  
  
  
  
              String sym = s.trim().toUpperCase();
  
  try {
  
  //csv file containing data
  String strFile = "companylist.csv";
  
  //create BufferedReader to read csv file
  BufferedReader br = new BufferedReader( new FileReader(strFile));
  String strLine = "";
  StringTokenizer st = null;
  int lineNumber = 0, tokenNumber = 0;
  
  //create arraylist
  ArrayList&lt;String&gt; arrayList = new ArrayList&lt;String&gt;();
  
  //read comma separated file line by line
  while( (strLine = br.readLine()) != null){
  
  lineNumber++;
  
  //break comma separated line using ","
  st = new StringTokenizer(strLine, ",");
  
  while(st.hasMoreTokens()){
  
  //display csv values
  tokenNumber++;
  
  arrayList.add(st.nextToken());
  //System.out.println("Line # " + lineNumber + ": "+ st.nextToken() + " " + st.nextToken());
  } //end small while
  
  //reset token number
  tokenNumber = 0;
  
  } //end big while loop
  
  //send csv to an array
  Object[] elements = arrayList.toArray();
  /*
  for(int i=0; i &lt; elements.length ; i++)    {
         System.out.println(elements[i]);
  
  } */
  Scanner input = new Scanner(System.in);
  System.out.print("Enter Ticker symbol");
  //String sym = input.next().toUpperCase(); //convert to uppercase to match csv
  int j=0;
  for(int i=0; i &lt; elements.length ; i++)    {
    if (((String) elements[i]).contains(sym)){
        //System.out.println(elements[i]);
  
        dtm.addRow(elements);
        j++;
        if (j==25) break; //only show this many results
    }
  
  
  }
  
  }
  catch(Exception e){
  System.out.println("Exception while reading csv file: " + e);
  }
      }
  }
  </code></pre>
  
  <p>I understand why this is happening but I am not sure how to tell it to print the correct lines since I can't use dtm.addRow(elements[i]);</p>
  
  <p>Any help is greatly appreciated. </p>