Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Convert String to Array of Integers in Java



You can convert a String to integer using the parseInt() method of the Integer class. To convert a string array to an integer array, convert each element of it to integer and populate the integer array with them.

Example

 Live Demo

import java.util.Arrays;
public class StringToIntegerArray {
   public static void main(String args[]) {
      String [] str = {"123", "345", "437", "894"};
      int size = str.length;
      int [] arr = new int [size];
      for(int i=0; i<size; i++) {
         arr[i] = Integer.parseInt(str[i]);
      }
      System.out.println(Arrays.toString(arr));
   }
}

Output

[123, 345, 437, 894]
Updated on: 2023-09-06T12:59:19+05:30

44K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements