Integer Array to int Array Java


There may be a necessity to convert integer array to int array. For example, a DS stores only integer objects and it may be required to read the integer values into an int array. That is, Integer Array to int Array.
Following is the example on Integer Array to int Array.
public class IntegerTointArray
{
  public static void main(String args[])
  {                                                    // create integer array
    Integer marks[] = {new Integer(40), new Integer(50), new Integer(60)};
                                                       // create int array
    int marks1[] = new int[marks.length];
                                                       // assign the values of integer array elements to int array elements
    for(int i = 0; i < marks.length; i++)
    {
      marks1[i] = marks[i].intValue();
    }
                                                       // print int elements values
    for(int i = 0; i < marks1.length; i++)
    {
      System.out.println(marks1[i]);                   // prints 40, 50, 60
    }

    System.out.println(marks1[0]+marks1[1]+marks1[2]); // even yo can add; prints 150
  }
}

===================Extra Reading=============================

All Array Operations at a Glance

=============================================================

Leave a Comment

Your email address will not be published.