Java - Write code to Split String to Int Array

Description

Write code to Split String to Int Array

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String ids = "1,2,3";
        String spliter = ",";
        System.out.println(java.util.Arrays.toString(toIntArray(ids,
                spliter)));/*from  www .j a  v  a 2  s . co  m*/
    }

    public static Integer[] toIntArray(String ids, String spliter) {
        String[] temps = ids.split(spliter);
        Integer[] ia = new Integer[temps.length];
        for (int i = 0; i < temps.length; i++) {
            ia[i] = Integer.parseInt(temps[i]);
        }
        return ia;
    }
}

Related Exercise