jGuru Forums

vector of vectors
1 posts in topic
Flat View
TOPIC ACTIONS:

Posted By:   Sharen_Su
Posted On:   Thursday, June 27, 2002 10:48 PM

can somebody teach me how to use vector of vectors? because i need to retrieve the data from a text file and store it into vector.(i need to make use of the data stored in vector to compute some results) problem is my data in the text file is some sort like a table.. there are columns and rows. And i don't know how to make use of vector of vector.. in my codes, i make use of arraylist.. but then i hope to use vector of vectors instead. can someone kindly help me? FileInputStream fis=new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis=new DataInputStream(bis); List list = new ArrayList(); String str; while((str = dis.readLine())!= null)   More>>

can somebody teach me how to use vector of vectors? because i need to retrieve the data from a text file and store it into vector.(i need to make use of the data stored in vector to compute some results) problem is my data in the text file is some sort like a table.. there are columns and rows. And i don't know how to make use of vector of vector.. in my codes, i make use of arraylist.. but then i hope to use vector of vectors instead. can someone kindly help me?

```
FileInputStream fis=new FileInputStream(f);

BufferedInputStream bis = new BufferedInputStream(fis);

DataInputStream dis=new DataInputStream(bis);

List list = new ArrayList();

String str;

while((str = dis.readLine())!= null)

{

StringTokenizer st = new StringTokenizer(str, " ");

while (st.hasMoreTokens())

{

out.println(st.nextToken()+"*");

}

list.add(str);

out.println("

");

}

dis.close();

```
<<Less

Re: vector of vectors

Posted By:   Lasse_Koskela
Posted On:   Thursday, June 27, 2002 10:58 PM

`FileInputStream     fis = new FileInputStream(f);BufferedInputStream bis = new BufferedInputStream(fis);DataInputStream     dis = new DataInputStream(bis);           String row;String col;Vector rows = new Vector();Vector cols = null;// loop through rowswhile((row = dis.readLine())!= null){      StringTokenizer st = new StringTokenizer(row, "	");    // create a new Vector for each row's columns    cols = new Vector();    // loop through columns    while (st.hasMoreTokens())     {          cols.add(st.nextToken());    }    // add the column Vector to the rows Vector    rows.add(cols);}dis.close();`