Results 1 to 2 of 2
  1. #1
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default Create an array of Vectors

    How do I create an array of Vectors? Suppose I want a regular old array of Vectors that hold Strings.

    Java Code:
    private Vector<String>[] list;
    ...
    list = new Vector<String>[5];
    I get a compiler error complaining about generic array creation.

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

    Default

    For one, I would use ArrayList and not Vector, Vector has a lot of overhead that you don't need. Secondly, the error message is right, you can't create a "generitised" array. Again, use an ArrayList.

    Java Code:
    List<List<String>> list = new ArrayList<List<String>>();
    list.add(new ArrayList<String>());
    list.get(0).add("Whatever");

Similar Threads

  1. How do I create an array with every cycle of a loop?
    By blackhole8746 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 07:49 AM
  2. Replies: 0
    Last Post: 04-23-2008, 08:15 PM
  3. Replies: 0
    Last Post: 04-14-2008, 08:43 PM
  4. How do I create an Array of Images
    By wco5002 in forum New To Java
    Replies: 3
    Last Post: 03-21-2008, 03:45 PM
  5. Vectors of Vectors or hash-somethings?
    By mindwarp in forum New To Java
    Replies: 3
    Last Post: 03-10-2008, 02:57 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
  •