Forum Stats

  • 3,760,207 Users
  • 2,251,664 Discussions
  • 7,871,021 Comments

Discussions

How to declare an array of Vector<double[]> ?

843793
843793 Member Posts: 41,732 Green Ribbon
edited May 27, 2010 10:54AM in Generics
Hi,
would like to declare an array of Vector<double[]>.
How to tell this the compiler ?
Thanks

Predict.java:36: ';' expected
private Vector<double[]> test[]=new Vector<double[]>[ 3 ]();

Predict.java:36: generic array creation
private Vector<double[]> test[]=new Vector<double[]>[ 3 ];

Comments

  • 843793
    843793 Member Posts: 41,732 Green Ribbon
     private Vector<double[]> test[] = null; // compiles OK
     private Vector<double[]>[] test = null; // also compiles OK
    The problem is that you can't do this ( error: generic array creation )
      test = new Vector<double[]>[3];
    You can try this, but you'll get a warning:
      test = new Vector[3];
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    Thanks edsonw for your answer.
    Well, after declaring the arrays
    I would like to use them.
    Therefor I have to call the new-statement.
    As you have shown:

    test = new Vector<double[]>[3]; // error
    test = new Vector[3]; // warning

    doesn't work.
    Is there any new-statement,
    which generates no errors, nor warnings ?
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    Is there any new-statement,
    which generates no errors, nor warnings ?
    Yes:
    Vector<Vector<double[]>> test = new Vector<Vector<double[]>>();
    Or better yet, use ArrayList, as all of Vector's methods are synchronized, which you probably don't need.
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I have declared a list of Arrays like this and now i dont know how to insert an object into it
    private List <List<Post[]>> list = new ArrayList<List<Post[]>>();

    I have tried this to insert an object in the array but it doesn�t work
    list.add(List <Post[]> new Post());

    where Post is a classe created by me.

    how do i do to insert an object?
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    edited Mar 21, 2008 4:46AM
    // "list" is  a list of List<Post[]>, so we can add one like that
    List <List<Post[]>> list = new ArrayList<List<Post[]>>();
    list.add(new ArrayList<Post[]>());
    
    // why not add an element? 
    list.get(0).add(new Post[] { new Post() });
    Edited by: BIJ001 on 2008.03.21. 9:46
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    I declared this:

    private Set<HashSet<Post[]>> blog = new HashSet<HashSet<Post[]>>();

    then

    blog.add(new HashSet<Post[]>());

    but i dont know how to insert an object into it.

    i make this:

    blog.get

    but only appears getClass and i wanted get, so that i could use it like a list.
    Can someone helpe me to insert an object into into.
    thanks it�s a bit urgent
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    edited May 26, 2010 9:04PM
    Hello...

    I had a similar problem, I solved using Double object not double Double object...


    Lucky
    Use:
    private Vector<Double[]> test[]=new Vector<Double[]>[ 3 ]();
    not use
    private Vector<double[]> test[]=new Vector<double[]>[ 3 ]();
    Lucky from Colombia...

    Edited by: joseluisbz.hotmail on May 26, 2010 6:02 PM
  • 843793
    843793 Member Posts: 41,732 Green Ribbon
    edited May 27, 2010 10:44AM
    joseluisbz.hotmail wrote:
    Use:
    private Vector<Double[]> test[]=new Vector<Double[]>[ 3 ]();
    1. That has syntax errors (you cant do [3] AND ())
    2. Even if it didn't have syntax errors, it still wouldn't compile since you're still trying to create a generic array.
    3. This thread is over *2 years old*.

    Please don't resurrect long-dead posts to post an incorrect, untested "solution."
  • PhHein
    PhHein Member, Moderator Posts: 7,169 Silver Trophy
    Incorrect zombie resurrection deleted and thread locked.
This discussion has been closed.