Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2009, 05:10 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default 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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-20-2009, 09:01 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
JosAH is on a distinguished road
Default
What is your 'vector' class? (lowercase 'v')

kind regards,

Jos
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-20-2009, 09:21 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Sorry just a misspell when i posted, it should be Vector<Vector> rowDataIn = new Vector<Vector>
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-20-2009, 09:26 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Do you understand what my problem is? my bad English makes it hard for me to explain.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-21-2009, 09:45 AM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
JosAH is on a distinguished road
Default
Originally Posted by ocean View Post
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-21-2009, 10:06 AM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-21-2009, 11:36 AM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
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]
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-21-2009, 12:43 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Solved it! Thanks anyway.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-21-2009, 12:54 PM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,270
Rep Power: 3
JosAH is on a distinguished road
Default
Originally Posted by ocean View Post
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-21-2009, 02:13 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-21-2009, 02:37 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 11-21-2009, 03:17 PM
Senior Member
 
Join Date: Sep 2009
Location: Sweden/Borås
Posts: 107
Rep Power: 0
ocean is on a distinguished road
Default
Hmm indeed, I think your rigth. Will need more reading tho. Thankś for pointning me there.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vector sanox New To Java 20 09-01-2009 05:21 PM
Vector MuslimCoder Advanced Java 4 08-06-2009 04:44 PM
Vector<Point2D> list = new Vector<Point2D>();Is it possible for 15,000 Point2D obj??? Mazharul Java 2D 1 04-06-2009 07:45 AM
vector - get natdizzle New To Java 2 01-02-2009 05:09 AM
Vector help king_arthur New To Java 3 01-22-2008 08:33 PM


All times are GMT +2. The time now is 03:31 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org