hello everyone i hope someone can help me I have this code which prints out a line from the csv file but if you look at my code. Where it says if (i%10 == ((Integer)arr2.get(arr2.size()-1)).intValue()) this will read in the last item that is in the arraylist (arr2) by getting the integer value. but i want it to read out all the values that are inside the arraylist arr2 how could i do this? please could some one help me thanks ben import java.io.*; import java.util.*; import java.lang.*; import java.util.StringTokenizer.*; import java.sql.*;
public class RT2 {
public static void main(String[] args) { String token = null; String currentToken = ""; Hashtable hh = new Hashtable(); ArrayList arr2 = new ArrayList(); String st1 = "ben"; String st2 = "ben"; //table names String st3 = "alex"; String st4 = "alex"; String st5 = "ben"; String st6 = "matt"; String st7 = "mum"; String st8 = "mum"; String st9 = "dad"; String st10 = "ben"; try { Vector v2 = new Vector(100); Vector v = new Vector(100); FileReader file = new FileReader("Work.csv"); BufferedReader buff = new BufferedReader(file); String line = buff.readLine(); StringTokenizer s = null; boolean eof = false; while (!eof){ s = new StringTokenizer(line.trim(),",",true); boolean lastToken = true; while (s.hasMoreTokens()) { token = s.nextToken(); if (lastToken){ if (token.equals(",")) { v.add(""); } lastToken = false; } if (! token.equals(",")) { v.add(token); } else { if (currentToken.equals(",")) { v.add("");
Then instead of getting the one item from the list, you should iterate through the list.
By the way, why are you using this hodgepodge of Vectors, ArrayLists and Hashtables? Your code will be much simpler and cleaner if you consolidate it to use just Lists and Maps. I would also stick with using Iterators instead of Enumerations.