Click to See Complete Forum and Search --> : Accessing a list iniside a list
Rabbit3cat
02-10-2006, 01:37 PM
Hi i have a list of lists containing strings, and i want to seperate them. I have written some code to access the inner lists
Iterator it = newList.iterator();
while(it.hasNext()){
Object f = it.next();
}
What i want to do now is store each object f as a seperate list. Does anybody know how to do this.
Thanks
BigDog
02-10-2006, 01:45 PM
Do you want to store each objct f AS a seperate list or store each f in a seperate list?
Those would be decidedly different questions.
*corrected bad english*
Rabbit3cat
02-10-2006, 02:07 PM
sorry i want to store each f object in a seperate list. For example
List Before = [[hello, one, two], [six, go, to, nine],[tree, light, seven]]
each inner list (f) is to be stored in a seperate list so the result would be:
list1 [hello, one, two]
list2 [six, go,to,nine]
list3 [tree,light,seven]
Sorry if that was unclear the first time!
chazzy
02-10-2006, 02:46 PM
would an array suffice for this?
Rabbit3cat
02-10-2006, 02:49 PM
Yes i am actually trying to implement it as an array now but not having any luck. The reason i need to seperate the lists is because i need to iterate through the words in each list and compare each word in each list to a given string. I thought list would be the best way to seperate them but if you know a way to do it using arrays i would be very glad to hear it!
Cytael
02-12-2006, 07:19 PM
2-D array with a double for loop to iterate would seem to be the easy way, especially if you know the size of the lists before-hand:
String[][] ListBefore;
int constraint1 = 3, contraint2 = 3;
for(int i=0; i<constraint1; i++)
{
for(int j=0; i<constraint2; j++)
{
if(ListBefore[i][j].equals("check string"))
{
//do something
}
}
}
Rabbit3cat
02-14-2006, 05:31 AM
Great got that working, thanks for all the help!