Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Why it doesn't work? (use o Vector)

  Asked By: Frankie    Date: Jul 05    Category: Java    Views: 7526
  

import java.*;
import java.util.*;


public class prova{

public static void main(String args[]){

Integer arr1[]=new Integer[2];
Integer arr2[]=new Integer[2];
Vector vettore=new Vector();
vettore.add(arr1);
arr2=vettore.get(1);
}
}

What is the right manner to do it working? and why.


Share: 

 

2 Answers Found

 
Answer #1    Answered By: William Bouchard     Answered On: Jul 05

Instead of

arr2=vettore.get(1);

try

arr2 = (Integer[])vettore.get(0);

 
Answer #2    Answered By: Jean Bell     Answered On: Jul 05

improved code:

import java.*;
import java.util.*;


public class  prova{

public static  void main(String args[]){

Integer arr1[]=new Integer[2];
Integer arr2[]=new Integer[2];
Vector vettore=new Vector();
vettore.addElement(arr1);
arr2=(Integer[]) vettore.elementAt(0);
}
}

> What is the right manner to do it working? and why.
Casting is done when you take something out of a Vectro because
Vectors only store Objects handles. The other method calls were just
wrong. Oh and vectors start counting their elements at 0.

 
Didn't find what you were looking for? Find more on Why it doesn't work? (use o Vector) Or get search suggestion and latest updates.




Tagged: