|
Re: Array of a vector
|
Posted: Jan 22, 2003 12:56 PM
|
|
I think I understand what you're trying to do, you want a list with an entry for each 'line' in your file. Each 'line' entry should itself be a list, with some elements for the contents of that line.
You might try something like the following:
List allLines = new ArrayList();
while (dataAvailable) {
String newData = readline();
if (newData.startswith('LINE') {
List lineList = new ArrayList();
addDataToLineList(); //or however you're parsing the different parts of your list
allLines.add(lineList);
}
}
This will create one List called 'allLines', and insert into it as many new Lists as there are 'LINE' entries in your file.
Scoping rules dictate that you won't have a named reference to any of those internal lists outside the loop, so if you want to do something with them, you'll have to iterate.
As a side note, you probably want to use ArrayLists, they're basically the same as Vectors, except they're substantially faster because they're not synchronized.
Another side note, if your 'LINE' entries are all formatted the same (like "LINE 0 name1 name2 address1 .. ect), you may want to make some little inner class that will parse the string into discrete fields, and provide accessors, and put that in the List rather than a vector.
-Kevin
|
|