
11-20-2009, 05:10 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
Vector<vector> loop thru
SOLVED
Evening, new problem that makes my hair grey, if i have a
|
Code:
|
Vector<vector> rowDataIn = new Vector<vector>
rowDataIn.add(1);
rowDataIn.add(2); |
And i loop it thru with.
|
Code:
|
Iterator iterator = rowDataIn.iterator();
while (iterator.hasNext()){
done = iterator.next();
} |
It just loop thru the first one. Leaving the Object done with the result [1, 2] and not 1 2 as i would like. How can this be solved?
Last edited by ocean; 11-21-2009 at 12:44 PM.
|
|

11-20-2009, 09:01 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
|
|
|
What is your 'vector' class? (lowercase 'v')
kind regards,
Jos
|
|

11-20-2009, 09:21 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
|
Sorry just a misspell when i posted, it should be Vector<Vector> rowDataIn = new Vector<Vector>
|
|

11-20-2009, 09:26 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
|
Do you understand what my problem is? my bad English makes it hard for me to explain.
|
|

11-21-2009, 09:45 AM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
|
|
Originally Posted by ocean
|
|
Do you understand what my problem is? my bad English makes it hard for me to explain.
|
Your English is fine but what exactly is your problem? The outer vector contains vectors, I understood that, but what do you want to do with them?
kind regards,
Jos
|
|

11-21-2009, 10:06 AM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
|
Im sending the data to a file, and i want the format data,data,data. And not [data,data,data]. I need someway too loop the Object done.
if i write out the vector before any loop it looks like --> [[data,data,data]]
I Use Iterator and after the loop it looks like this --> [data,data,data]
I Need another loop so it looks like this --> data,data,data
My problem is that after the first loop my Vector has turned into an Object and i cant use Iterator on it.
Last edited by ocean; 11-21-2009 at 10:09 AM.
|
|

11-21-2009, 11:36 AM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
I realise now that i have posted wrong. It should be as follow.
|
Code:
|
Vector<Vector> v = new Vector<Vector>
Vector<String> s = new Vector<String>
s.addElement("One");
s.addElement("Two");
s.addElement("Three");
v.add(s); |
Now itś correct, how do i loop thrue the v Vector so the result will be
One Two Three.
And not [One,Two,Three]
|
|

11-21-2009, 12:43 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
|
Solved it! Thanks anyway.
|
|

11-21-2009, 12:54 PM
|
|
Senior Member
|
|
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
|
|
Originally Posted by ocean
|
I realise now that i have posted wrong. It should be as follow.
|
Code:
|
Vector<Vector> v = new Vector<Vector>
Vector<String> s = new Vector<String>
s.addElement("One");
s.addElement("Two");
s.addElement("Three");
v.add(s); |
Now itś correct, how do i loop thrue the v Vector so the result will be
One Two Three.
And not [One,Two,Three]
|
I don't know what you have in mind exactly but when I print vector v I get [[One, Two, Three]] as I expected (a vector with one element which is a vector containing three elements).
kind regards,
Jos
|
|

11-21-2009, 02:13 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
|
What i have in mind is to save the userinput from JTable into a file as data;data;data. wich it now does. But as I solved 1 problem next is just arund the corner.
It saves it all in one row. Somehow i need to count columns and add a \n at the end.
Anyone has experience at saving from JTable to File, And Read it back from File to JTable? And that mabey could give me some advice ow this is best done.
|
|

11-21-2009, 02:37 PM
|
 |
Moderator
|
|
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
|
|
|
Hm, serialize the data might be an option. Have you gone through the Serialization tutorial at the Sun tutorials?
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
|
|

11-21-2009, 03:17 PM
|
|
Senior Member
|
|
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
|
|
Hmm indeed, I think your rigth. Will need more reading tho. Thankś for pointning me there.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +2. The time now is 03:31 PM.
|
|