Reflection & primitive arrays

hello,
I call some methods with reflection.....As you know method.invoke(....) returns an instance of Object......I saw on javadoc that primitive data types are wrapped into their corrispondent object:es int->Integer......My problem is with primitive data types arrays: if I have int[] as return type and I cast Object to Integer[] I receive CastException...I tried to discover instance type with reflection, but nothing useful ( something as "[[I" )
How to solve it?
Many thanks.
Paolo                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

You may find this helpful ... it shows some of the methods that you can use to discover more about the type of an array via reflection.
import java.lang.reflect.Array;
public class PrimArrayReflect
    public static void main(String[] argv)
    throws Exception
        int[] a = new int[10];
        System.out.println(a.getClass().toString());
        System.out.println(a.getClass().isArray());
        System.out.println(a.getClass().getComponentType().toString());
        System.out.println(a.getClass().getComponentType().equals(Integer.TYPE));
        Array.setInt(a, 0, 123);
        System.out.println(a[0]);
}

Similar Messages

  • Trouble with primitive arrays and casting, lesson 521

    hi everyone!
    there is a problem i discovered right now - after years with java where was no necessity to do this.....
    and i'm shure this must have been the topic already, but i couldn't find any helpful resource :-/
    right here we go:
    1. an array is a (special) kind of object.
    2. there are "primitive" arrays and such containing references to objects. of course - and i imagine why - they are treated differently by the VM.
    3. then both are - somehow - subclasses of Object. whereas primitive types are not really, primitive-arrays are. this is hidden to the programmer....
    4. any array can be "pointed" at via local Object variable, like this:
    Object xyz = new int[6];
    5. arrays of Objects (with different dimensions) can be casted, like this:
      Object pointer = null;
      Object[]   o  = new SomeClass[42] ;
      Object[][] oo = new OtherClass[23] [2] ;
      Object[][][] ooo = new OtherClass[23] [2] [9] ;
      o = oo = ooo;     // this is save to do,
                                   //because "n-dimensional" object-arrays
                                  // are just arrays of  other arrays, down to simple array
    pointer = o;         // ok, we are referencing o via Object "pointer"6. but, you cannot do this with primitive types:
      int[]  i1 = new int [99] ;
      int[][] i2 = new int [1] [3] ;
      i1 = i2                  // terror: impossible. this is awful, if you ask me.
                                   // ok, one could talk about "special cases" and
                                   // "the way the VM works", but this is not of interest to me as
                                   // a programmer. i'm not happy with that array-mess!
      pointer = i2;       // now this is completely legal. i2, i1 etc is an object!7. after the preparation, let's get into my main trouble (you have the answer, i know!) :
    suppose i have a class, with methods that should process ANY kind of object given. and - i don't know which. i only get it at runtime from an unknown source.
    let's say: public void BlackBox( Object x );
    inside, i know that there might be regular objects or arrays, and for this case i have some special hidden method, just for arrays... now try to find it out:
    public void BlackBox( Object x )
      if ( x == null)
           return;
       Class c = x.getClass();
       if ( c.isArray() )
              // call the array method if it's an array.........
              BlackBoxes(     (Object [] )  x );         // wait: this is a cast! and it WILL throw an exception, eventually!
              return;
       else
               DoSpecialStuffWith( x );
    }ok ? now, to process any kind of array, the special method you cannot reach from outside:
    private void BlackBoxes( Object[] xs )
       if ( xs != null )
            for ( Object x : xs )
                 BlackBox( x );
    // this will end up in some kind of recursion with more than one array-dimension, or when an Object[] has any other array as element!this approach is perfectly save when processing any (real) Object, array or "multi-dimensional" arrays of Objects.
    but, you cannot use this with primitive type arrays.
    using generics wouldn't help, because internally it is all downcasted to Object.
    BlackBox( new Integer(3) ) ---- does work, using a wrapper class
    BlackBox( new Integer[3] ) ----- yep!
    BlackBox( 3 ) ---- even this!
    BlackBox( new int[42] ) ---- bang! ClassCastException, Object[] != int[]
    i'm stuck. i see no way to do this smoothly. i could write thousands of methods for each primitive array - BlackBox( int[] is ) etc. - but this wouldn't help. because i can't cast an int[][] to int[], i would also have to write countless methods for each dimension. and guess, how much there are?
    suppose, i ultimately wrote thousands of possible primitive-type methods. it would be easy to undergo any of it, writing this:
    BlackBox( (Object) new int[9] [9] );
    the method-signature would again only fit to my first method, so the whole work is useless. i CAN cast an int[] to Object, but there seems no convenient way to get the real array out of Object - in a generic way.
    i wonder, how do you write a serialisation-engine? and NO, i can't rely on "right usage" of my classes, i must assume the worst case...
    any help appreciated!

    thanks, brigand!
    your code looks weird to me g and i think there's at least one false assumption: .length of a multidimensional array returns only the number of "top-level" subarrays. that means, every length of every subarray may vary. ;)
    well i guess i figured it out, in some way:
    an int is no Object;
    int[ ] is an Object
    the ComponentType of int [ ] is int
    so, the ComponentType of an Object int[ ] is no Object, thus it cannot be casted to Object.
    but the ComponentType of int [ ] [ ] IS Object, because it is int [ ] !
    so every method which expects Object[], will work fine with int[ ] [ ] !!
    now, you only need special treatment for 1-dimensional primitive arrays:
    i wrote some code, which prints me everything of everything:
        //this method generates tabs for indentation
        static String Pre( int depth)
             StringBuilder pre = new StringBuilder();
             for ( int i = 0; i < depth; i++)
                  pre.append( "\t" );
             return pre.toString();
        //top-level acces for any Object
        static void Print( Object t)
             Print ( t, 0);
        //the same, but with indentation depth
        static void Print( Object t, int depth)
            if ( t != null )
                 //be shure it is treated exactly as the class it represents, not any downcast
                 t = t.getClass().cast( t );
                if ( t.getClass().isArray() )
                     //special treatment for int[]
                     if ( t instanceof int[])
                          Print( (int[]) t, depth);
                     // everything else can be Object[] !
                     else
                          Print( (Object[]) t, depth );
                     return;
                else
                    System.out.println( Pre(depth) + " [ single object:] " + t.toString() );
            else
                System.out.println( Pre(depth) + "[null!]");
        // now top-level print for any array of Objects
        static void Print( Object [] o)
             Print( o, 0 );
        // the same with indentation
        static void Print( Object [] o, int depth)
            System.out.println( Pre(depth) + "array object " + o.toString() );
            for ( Object so : o )
                    Print( so, depth + 1 );
        //the last 2 methods are only for int[] !
        static void Print( int[] is)
             Print( is, 0 );
        static void Print( int[] is, int depth)
            System.out.println( Pre(depth) + "primitive array object " + is.toString() );
            // use the same one-Object method as every other Object!
            for ( int i : is)
                 Print ( i, depth + 1 );
            System.out.println( "-----------------------------" );
        }now, calling it with
    Print ( (int) 4 );
    Print ( new int[] {1,2,3} );
    Print( new int[][] {{1,2,3}, {4,5,6}} );
    Print( new int[][][] {{{1,2,3}, {4,5,6}} , {{7,8,9}, {10,11,12}}, {{13,14,15}, {16,17,18}} } );
    Print( (Object) (new int[][][][] {{{{99}}}} ) );
    produces this fine array-tree:
    [ single object:] 4
    primitive array object [I@9cab16
          [ single object:] 1
          [ single object:] 2
          [ single object:] 3
    array object [[I@1a46e30
         primitive array object [I@3e25a5
               [ single object:] 1
               [ single object:] 2
               [ single object:] 3
         primitive array object [I@19821f
               [ single object:] 4
               [ single object:] 5
               [ single object:] 6
    array object [[[I@addbf1
         array object [[I@42e816
              primitive array object [I@9304b1
                    [ single object:] 1
                    [ single object:] 2
                    [ single object:] 3
              primitive array object [I@190d11
                    [ single object:] 4
                    [ single object:] 5
                    [ single object:] 6
         array object [[I@a90653
              primitive array object [I@de6ced
                    [ single object:] 7
                    [ single object:] 8
                    [ single object:] 9
              primitive array object [I@c17164
                    [ single object:] 10
                    [ single object:] 11
                    [ single object:] 12
         array object [[I@1fb8ee3
              primitive array object [I@61de33
                    [ single object:] 13
                    [ single object:] 14
                    [ single object:] 15
              primitive array object [I@14318bb
                    [ single object:] 16
                    [ single object:] 17
                    [ single object:] 18
    array object [[[[I@ca0b6
         array object [[[I@10b30a7
              array object [[I@1a758cb
                   primitive array object [I@1b67f74
                         [ single object:] 99
    -----------------------------and i'll have to write 8 methods or so for every primitive[ ] type !
    sounds like a manageable effort... ;-)

  • Implementing an ArrayList as a Primitive Array. Plzzz Help a Newbie!!!

    Hi I am a newbie to Java,
    I have the following question, could someone please demonstrate some code to answer it?...
    Q)
    The Java class ArrayList uses a primitve array as its internal data structure and provides methods to access the array elements.
    Write a implentation of a basic version of ArrayList providing methods to get, set, insert and delete elements. It should be possible to insert and delete at any position within the ArrayList. The methods should throw exceptions as necessary. Include one or more appropriate constructors.
    Thanks in advance
    Carl

    Hi I am a newbie to Java,
    I have the following question, could someone please
    demonstrate some code to answer it?...
    Q)
    The Java class ArrayList uses a primitve array as its
    internal data structure and provides methods to
    access the array elements.
    Write a implentation of a basic version of ArrayList
    providing methods to get, set, insert and delete
    elements. It should be possible to insert and delete
    at any position within the ArrayList. The methods
    should throw exceptions as necessary. Include one or
    more appropriate constructors.
    Thanks in advance
    CarlNo it doesn't. It uses an object array. The question itself demonstrates that the author was either sleepy or not very knowledgeable to begin with as they either consider an array of objects a "primitive array" or they think all arrays are primitives.
    Regardless, what I suspect they want from you is more or less a Collection backed by an array. For an example of one look at ArrayList's source code to begin with.

  • Using Primitive Arrays in JPA

    Is it possible to persist and store arrays of primitive types using the Java Persistence API? If so, is there any special annotation that the array requires?

    Don't use ASSOC Arrays. Use SETs.
    Also increase the JTA timeout in Weblogic to like say 600 seconds.

  • Returning primitives array (i.e. long[]) in java sp, how to 'call spec'?

    Hi,
    When I write a java sp returning a long[], how can I write a
    call spec in PL/SQL,
    is anyone having any ideas?
    thanks, first.

    Try Changing your namespace for java to ConvertDate2(This class should be in classpath) and replace
    <stringdate><xsl:variable name="stringDate" select="java:ConvertDate2.changeDate(ds_start_date)"/>
    </stringdate>
    with
    <stringdate><xsl:variable name="stringDate" select="java:changeDate(ds_start_date)"/>
    </stringdate>
    Make sure your query matches with ds_start_date correctly.

  • Arrays.asList for primitives

    Ok, this may sound like a stupid question, but I've checked the java API and searched this forum and cant find an answer, so here goes:
    Is there any equivilent for Arrays.asList for arrays of primitives? I need to get an array of ints in to a list.
    Is my hangover just causing me to miss something really stupid?

    In case anyone in Sun is listening...
    Please provide a class/method for creating human-readable Strings from the following...
    int[]
    byte[]
    float[]
    and any other primitive arrays.

  • The Mysterious java array implementation

    In java when we create an array of primitive data type
    e.g long[] x = new long[10];
    we can reterieve the lenght of the array using x.length. Does someone know where this variable length is declared. As in java arrays are implemented as an Objects. Even i treid to find out the class reference variable "x" belongs to, and I came to know that it is "[J" and this class implements Cloneable and Seriaziable interface. But there is no field or variable like "length".                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Java-Aspirant wrote:
    . Even i treid to find out the class reference variable "x" belongs to, and I came to know that it is "[J" and this class implements Cloneable and Seriaziable interface. But there is no field or variable like "length".
    If you want to use reflection on arrays, there's  [java.lang.reflect.Array|http://java.sun.com/javase/6/docs/api/java/lang/reflect/Array.html which allows you to interrogate the length pseudo-field and access elements.

  • How to send a Varying Array param to a PL/SQL Stored Procedure from Java

    * I am VERY new to jdbc, and even somewhat new to Java
    * I'm using Java 1.5, Oracle 10g.
    * I need to call the following PL/SQL Stored Procedure from Java:
    procedure setEventStatus
    i_deQueueStatus in deQueueStatus_type
    *deQueueStatus_type is the following (an array of deQueueStatus_OBJ):
    CREATE OR REPLACE TYPE deQueueStatus_OBJ as object
    eventID number (20),
    dequeuestatus varchar2(20)
    CREATE OR REPLACE TYPE deQueueStatus_TYPE IS VARYING ARRAY(500) of deQueueStatus_obj
    *I have created a Java object as follows:
    public class EventQueueDeQueueStatus
         long      eventID;
         String      dequeueStatus;
         EventQueueDeQueueStatus(long eventID, String dequeueStatus)
              this.eventID = eventID;
              this.dequeueStatus = dequeueStatus;
    I have an ArrayList of these.
    I need to pass this list to the Stored Procedure. How do I create a java.sql.Array so I can call CallableStatement.setArray to set the parameter? Or do I use something else? I have tried setObject with both the ArrayList and also with a primitive array, but got "Invalid Column Type" both times.
    Any help would be greatly appreciated. I just got this task today, and I have to make it work by Tuesday :-( !
    Thanks,
    Kathy

    Kathy,
    Search the archives of this forum and the JDBC forum for the terms STRUCT and ARRAY and you can find some sample code on the JDBC How-To Documents page and the JDBC Samples which can both be accessed from this page:
    http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html
    Good Luck,
    Avi.

  • Saving an integer array into a .txt file

    hii, im only a beginner in java, so this is the only code i've learned so far for saving array elements into a file
         public static void saveNames(String [] name) throws IOException
                   FileWriter file = new FileWriter("Example\\names.txt");
                   BufferedWriter out = new BufferedWriter(file);
                   int i = 0;
                   while (i < name.length)
                             if (name[i] != null)
                                  out.write(name);
                                  out.newLine();
                                  i++;
                   out.flush();
                   out.close();
    However, this is only used for string arrays; and i can't call the same method for an integer array (because it's not compatible with null)
    I don't really understand this code either... since my teacher actually just gave us the code to use, and didn't really explain how it works
    I have the same problem for my reading a file code as well --> it's only compatible with string
         public static String [] readNames (String [] name) throws IOException
              int x = 0;
              int counter = 0;
              String temp = "asdf";
              name = new String [100];
              FileReader file = new FileReader("Example\\names.txt");
              BufferedReader in = new BufferedReader(file);
              int i = 0;
              while (i < array.length && temp != null)                    // while the end of file is not reached
                   temp = in.readLine();
                   if (temp != null)
                        name[i] = temp;                    // saves temp into the array
                   else
                        name[i] = "";
                   i++;
              in.close();                                   // close the file
              return name;
    Could someone suggest a way to save elements from an integer array to a file, and read integer elements of that file?
    Or if it's possible, replace null with a similar variable (function?), that is suitable for the integer array (i can't use temp != 0 because some of my elements might be 0)
    Thanks so much!!!!!

    because it's not compatible with nullI think it should be okay to just remove the null condition check since there are no null elements in a primitive array when writing.
    Use Integer.parseInt() [http://java.sun.com/javase/6/docs/api/java/lang/Integer.html] to convert the String into an Integer when you read it back and use Integer.toString() to be able to write it as a String.

  • Sorting a two dimensional array in descending order..

    Guy's I'm a beginning Java programmer. I've been struggling with finding documentation on sorting a two dimensional primitive array in descending order.. The following is my code which goes works, in ascending order. How do I modify it to make the list write out in descending order?
    class EmployeeTable
         public static void main(String[] args)
         int[][] hours = {
              {2, 4, 3, 4, 5, 8, 8},
              {7, 3, 4, 3, 3, 4, 4},
              {3, 3, 4, 3, 3, 2, 2},
              {9, 3, 4, 7, 3, 4, 1},
              {3, 5, 4, 3, 6, 3, 8},
              {3, 4, 4, 6, 3, 4, 4},
              {3, 7, 4, 8, 3, 8, 4},
              {6, 3, 5, 9, 2, 7, 9}};
         int [] total = new int [hours.length];
         for (int i = 0; i < hours.length ; i++){
              for (int j = 0; j < hours.length ; j++){
                   total[i] += hours[i][j];
         int[] index = new int[hours.length];
         sortIndex(total, index);
    for (int i = 0; i < hours.length; i++)
    System.out.println("Employee " + index[i] + " hours are: " +
    total[i]);
    static void sortIndex(int[] list, int[] indexList) {
    int currentMax;
    int currentMaxIndex;
    for (int i = 0; i < indexList.length; i++)
    indexList[i] = i;
    for (int i = list.length - 1; i >= 1; i--) {
    currentMax = list[i];
    currentMaxIndex = i;
    for (int j = i - 1; j >= 0; j--) {
    if (currentMax < list[j]) {
    currentMax = list[j];
    currentMaxIndex = j;
    // How do I make it go in descending order????
    if (currentMaxIndex != i) {
    list[currentMaxIndex] = list[i];
    list[i] = currentMax;
    int temp = indexList[i];
    indexList[i] = indexList[currentMaxIndex];
    indexList[currentMaxIndex] = temp;

    Bodie21 wrote:
    nclow all you wrote was
    "This looks to me like a homework assignment that you're asking us to solve for you. Your description of what it does isn't even correct. It doesn't sort a 2d array.
    You would probably elicit better help if you could demonstrate that you've done some work and have something specific that you don't understand."
    To me that sounds completely sarcastic. You didn't mention anything constructive besides that.. Hence I called you a male phalic organ, not a rear exit...Bodie21, OK, now you've got 90% of us who regularly contribute to this forum thinking your the pr&#105;ck. Is that what you wanted to do? If so, mission accomplished. Many will be looking for your name next time you ask for help. Rude enough for you?

  • Storing 2d array in ArrayList?

    Hi I'm storing a 2d int array (int[][]) in an ArrayList. But I cant convert it back to a 2d array again.
    Tried:
    indices.add(option.getIndexList());
    indices.add(option[j].getIndexList());
    int[][] Arr = (int[][])indices.toArray(new int[indices.size()][2]);

    If you put a 2-d array into an ArrayList, then toArray would make a 3-d array--a 1-d array of 2-d arrays.
    However, I don't think you can use toArray to get a primitive array. If you look at the API, it requires an object. I think you'll have to do this to get each array:
    int [][] arr = (int[][])indices.get(0);If you want the 3-d array, you can do it manually.

  • BUG code insight declaration insert imports primitive types

    Facing this in JDEV 11g 11.1.1.3, studio edition install, bundled jdk1.6.0_18, JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660
    When using the 'Declaration Insert' code insight feature for method calls returning primitive arrays, JDev will add an import for the primitive return type. Using CTRL-ALT-V to do the same manually works correctly.
    Steps to replicate:
    - create a new class with a main method
    - inside main method type this code:
    "hello".
    - the code insight window will appear automatically (if using default code insight settings). Press "CTRL-Space" to access "Declaration Insert".
    - start typing "toCharArray", JDev will zero in on the toCharArray method which returns a char[], once selected, press enter to choose it.
    - jdeveloper generates the following code:
    char[] array = "hello".toCharArray();
    which is correct, but also adds an import statement in the beginning of the class:
    import char;
    which does not compile.
    - same behavior can be replicated with code like:
    new BigInteger("1").toByteArray();
    following the same pattern as above.

    although this post is way old it could do with a decent answer.
    some guidance can be taken from JSR26: UML Mapping for EJB
    find it a www.jcp.org
    also this research paper on consistency of reverse engineering between uml tools
    http://citeseer.nj.nec.com/545406.html
    Where Association is identified by looking at the types of all variables belonging >to a class (excluding method variables etc) and if the type of the variable is >non-primitive, than I have deduced it is an association relationship with that >class.
    Would this be the right approach?Yes. You could also say that if it is a java.* type then it would also be an attribute.
    Secondly I have noticed in JBuilder, it models dependency relationships by getting >all the Imports at the top of the java source file, is this right?? also I have >read that a dependency can be modelled by the variable types in operation >arguments (paremeterS ?)..JBuilder would be consistent with JSR26, and that's how i intend to implement in ArgoUml.
    I would also appreciate if someone could clarify the difference betweeen >Composition and Aggregation for me and explain if it is possible to identify the >two relationships directly from java source code..Composition is a stronger form of ownership. the composed class is owned only by 1 class. Its lifetime is strongly linked to its owner - ie. it is not created before its owner and it is destroyed before its owner is.
    eg. leg of a table.
    Agregation is weak ownership. the owned class may be owned by several classes.
    eg. a company is owned by many shareholders.
    Last but not least, what about multiplicity ? am I right in thinking that an >instance variable is 0-1, an array declaration is seen as 0-n (fixed number) and a >Vector/ data collection.. is seen as 0 - * (any number)..sound right.
    Alex

  • Creating OCI Arrays

    I am creating Oracle 9i Spatial objects, which have two VARRAYs. I am new to OCI. What is the usual way of creating with varrays in OCI? I can get the object created with OCIObjectNew, and append elements one at a time with OCICollAppend, but I am a little unhapy with this - I expected to be able to allocate storage for a number of elements, then set them one at a time. I distrust the overhead and fragmentation of memory using an append for each element.
    The OCI Guide provides no examples, and I can only find one example program writing a collection.
    Is there a way of allocating multiple entries for the varray at once ?
    Are there other examples of writing varrays or other collections?
    Thanks,
    David Penington

    Nope. Once you create an array, and give it a size, you're stuck with it. Its the same in any language that I've used (C, Pascal, Java...)
    If you need a larger array(ie add one more element in) you need to redeclare your array.
    There is a helper method that you can use:
    System.arrayCopy(...) will copy the values from one array to another for you.
    public String[] addName(String[] names, String newName){
      String[] newList = new String[names.length+1]);
      for (int i=0; i<names.length; i++){
        newList[i] = names;
    newList[newList.length-1] = newName;
    return newList;
    // somewhere in another method...
    public void testArray(){
    String[] names = new String[0];
    names = addName(names, "Bob");
    names = addName(names, "Bill");
    No its not wonderfully efficient, but thats how its done.
    The availability of the Collections framework for dynamically sized lists means that not being able to do it with primitive arrays isn't so important.

  • Array Insert/Update/Select in JDBC

    I've been using array processing in ODBC, OCI, and Pro*C for years and desperately need to do so in JDBC. I've thus far been unsuccessful and am beginning to doubt that it's supported which to me is unfathomable. I've likewise found many like inquiries on the net - none of which were addressed. There have been many respondants who don't undertstand what array processing is and mistake it for batch SQL statements. They are not the same. Batched SQL statements are seperate statements which are executed in a single call to the database engine. What I'm taking about is using a prepared statement and binding primitive arrays to the statement. A single statement is executed and the contents of the arrays passed to the database. I've conducted tests years ago and array insert/update is many times faster than batch statements. Does anyone know whether or not JDBC supports array processing? If anyone's interested, I can provide snippets via email which illustrate how this is done in ODBC and other API's.
    Thanks.

    You referred me to
    http://java.sun.com/products/jdbc/download.html. The
    only reference I found to arrays were SQL Arrays - not
    what I'm talking about. See prior C/ODBC snippet. Do
    you know how to do this in JDBC?You are talking about passing an array as a single parameter to and from the underlying database correct? (And that has nothing to do with batch processing.)
    If so in section 16.4 "Array Object"..... looking at that section gives the following reference....
    The Array object returned to an application by the ResultSet.getArray and
    CallableStatement.getArray methods is a logical pointer to the SQL ARRAY
    value in the database; it does not contain the contents of the SQL ARRAY value.
    The above has nothing to do with batch processing (although presumably one could use it in a batch process but then one can use String as well.)
    Of course perhaps there is something in there that says that only applies to batch processing. If so could you please point out the section and quote the text.

  • Wildcard for any types of Array?

    Hi,
    I want to create a method who convert an array of any type
    to an array of type Object.
    Is there a way to use a wildcard for the arrays like "T[]"
    My compiler - JBuilder 2005 - don't accept this.
    Olek

    You will have to build special cases for each primitive type. Basically, a series of (inputArray instanceof int[]) conditions, and in each you need to copy from the primitive array to the Object array (or the primitive-specific wrapper such as Integer[], depending on what you want).
    System.arraycopy() will not copy between primitive and reference type arrays, so that won't work.

Maybe you are looking for