Results 1 to 12 of 12
  1. #1
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default Vector<vector> loop thru

    SOLVED


    Evening, new problem that makes my hair grey, if i have a

    Java Code:
    Vector<vector> rowDataIn = new Vector<vector>
     rowDataIn.add(1);
     rowDataIn.add(2);
    And i loop it thru with.

    Java 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 11:44 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,458
    Blog Entries
    7
    Rep Power
    20

    Default

    What is your 'vector' class? (lowercase 'v')

    kind regards,

    Jos

  3. #3
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Sorry just a misspell when i posted, it should be Vector<Vector> rowDataIn = new Vector<Vector>

  4. #4
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Do you understand what my problem is? my bad English makes it hard for me to explain.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,458
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote 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

  6. #6
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    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 09:09 AM.

  7. #7
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    I realise now that i have posted wrong. It should be as follow.

    Java 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]

  8. #8
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Solved it! Thanks anyway.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,458
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ocean View Post
    I realise now that i have posted wrong. It should be as follow.

    Java 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

  10. #10
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    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.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hm, serialize the data might be an option. Have you gone through the Serialization tutorial at the Sun tutorials?

  12. #12
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Hmm indeed, I think your rigth. Will need more reading tho. Thankś for pointning me there.:)

Similar Threads

  1. Vector
    By sanox in forum New To Java
    Replies: 20
    Last Post: 09-01-2009, 04:21 PM
  2. Vector
    By MuslimCoder in forum Advanced Java
    Replies: 4
    Last Post: 08-06-2009, 03:44 PM
  3. Replies: 1
    Last Post: 04-06-2009, 06:45 AM
  4. vector - get
    By natdizzle in forum New To Java
    Replies: 2
    Last Post: 01-02-2009, 04:09 AM
  5. Vector help
    By king_arthur in forum New To Java
    Replies: 3
    Last Post: 01-22-2008, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •