How to convert/store a string of numbers in to an array in java?

You can convert a String to an 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.


 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]);


[123, 345, 437, 894]
Swarali Sree
Swarali Sree

I love thought experiments.