Click to See Complete Forum and Search --> : StringTokenizer into an Array?


Reno2005
12-10-2005, 11:55 AM
I am currently using StringTokenizer to read in an html file into lists but after each token is read into a list (listArea1 etc), i would like to add the same token into 1 of 4 arrays i.e.
listArea1 data is inserted into Array1,
listArea2 data is inserted into Array2,
listArea3 data is inserted into Array3,
listArea4 data is inserted into Array4,

This is where im at but i dont think im doing this correctly?

ArrayList array1 = new ArrayList ();
ArrayList array2 = new ArrayList ();
ArrayList array3 = new ArrayList ();
ArrayList array4 = new ArrayList ();

try
{
file = new DataInputStream((new URL(url)).openStream());
data = file.readLine();
clearLists();

while (data != null)
{
if(x >= start && x <= end)
{
StringTokenizer st = new StringTokenizer(data);
while(st.hasMoreElements())
{
listArea1.add(st.nextToken());
array1.add(st); //?Is this right?
listArea2.add(st.nextToken());
listArea3.add(st.nextToken());
listArea4.add(st.nextToken());
}
}
data = file.readLine();
x++;
}
}
Any help to get me onto the right track? :confused:
Thanks

Khalid Ali
12-11-2005, 10:10 AM
your question is not as, however if you want to keep a reference to the stringtokenizer at each loop, then yes you can use a list object and store all of the stringtokenizers in it for a later use..however if you want to do that then whats stopping you to keep just the whole stringtokenizer object in the list without going into the while loop at all?..
as I said its not clear what and why......

Reno2005
12-11-2005, 11:59 AM
Sorry if im not making it very clear, what i am trying to achieve is when the file is read in, the structure looks similar to,
4.8 GHJ 0.9 BAHM
7.9 JKM 0.2 MKJN

Currently it uses StringTokenizer to add the values into Lists, i.e.
List 1 ¦ List 2 ¦ List 3 ¦ List 4
4.8 ¦ GHJ ¦ 0.9 ¦ BAHM
7.9 ¦ JKM ¦ 0.2 ¦ MKJN

The way i understand it is that the values in the list are not registered into anything (i.e. array), they are only just split up via whitespaces.
I would like to sort i.e. List2 Alphabetically but i believe in order to do this they must be registered and if so how is it achieved?

Thanks