Results 1 to 8 of 8
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default How i add string array in vector

    I have string array how i add that array in vector
    I tried flowing code but not give me result
    Java Code:
    String[] jlf = {"Muhammad","Fahim","Aamir"};
    
    vector.addElement(jlf);

    Please give me idea how i add array in vector

    Thanks

  2. #2
    akaruppa is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default

    Hi,
    You need to use vector.addAll(Collection c) to achieve this.
    In order to convert array to Collection, u can use Arrays.asList(jlf)...

  3. #3
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default Maybe this help

    Vector <String[]> vector =new Vector();

    String[] jlf = {"Muhammad","Fahim","Aamir"};

    vector.add(jlf);

    String [] leer =null;

    for (int i = 0; i < vector.size(); i++)
    {
    leer= (String[]) (vector.get(i));
    for (int a=0;a<leer.length ;a++){
    System.out.println(leer[a]);
    }
    }

    *i'm searching a better way to acces the array inside the vector but this work very well by now.

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    confused, do you have a vector of an array of strings? or do you want the array of strings to be converted to a vector?

  5. #5
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    I have a vector of string.
    well i'm doing in the line
    Vector <String[]> vector =new Vector();
    is creating a Vector and each element in the vector will be an array of String, it will have the size and properties of the type String.

    if a do Vector vector = new Vector(); every element in the vector will be a Object insted of a String. Both can be use.

  6. #6
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    FYI, if you do this..

    Java Code:
    Vector<String[]> vector = new Vector<String[]>();
    instead of this...

    Java Code:
    Vector<String[]> vector = new Vector();
    then you can do this ...

    Java Code:
    leer = vector.get(i);
    instead of this...

    Java Code:
    leer = (String[]) vector.get(i);

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by artonlinehome View Post
    Vector <String[]> vector =new Vector();

    String[] jlf = {"Muhammad","Fahim","Aamir"};

    vector.add(jlf);

    String [] leer =null;

    for (int i = 0; i < vector.size(); i++)
    {
    leer= (String[]) (vector.get(i));
    for (int a=0;a<leer.length ;a++){
    System.out.println(leer[a]);
    }
    }
    Why did you simply copy and repost the unformatted code from above?

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 20 is the limit...

    Two things:
    1) He's not going to answer you
    2) I think he's trying to fill up the forum with nonsense posts so he can make to the 20 posts limit.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Convert a vector to a string array
    By orchid in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 02:31 AM
  2. Converting an Array to a Vector
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:44 PM
  3. Array or Vector
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 06:19 PM
  4. Replies: 1
    Last Post: 08-03-2007, 10:52 AM
  5. array vs Vector
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 07:07 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
  •