How to assign int value to integer variable

34,536

java 5 added autoboxing, so you should just be able to use this

int i=3;
Integer number=i;//number now equals 3

The reason you are getting an error is because you are using the array for indices and trying to add null at this indices. If you array was {100,101,102}, It would try to add null to intValues at index 100, 101, and 102, which don't exist, giving you the IndexOutOfBoundsEception;

Share:
34,536
Admin
Author by

Admin

Updated on April 29, 2020

Comments

  • Admin
    Admin about 4 years

    How can I convert an int value to integer value?

    Here is my code-

    private static int[] value= {R.drawable.collection1,R.drawable.collection2}
    
    public static ArrayList<Integer> AddIntValue (int[] value){
        ArrayList<Integer> Intvalue=new ArrayList<Integer>();
    
        for(int i=0;i<value.length; i++)
        {
            Intvalue.add(Integer.valueOf(value[i]), null);
        }
    
        return Intvalue;
    }
    

    Am getting error on Intvalue.add(Integer.valueOf(value[i]), null);

    Please help me

    Thanks