Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


Java – String to ArrayList conversion


In this program we are converting a String to ArrayList. The steps involved are as follows:
1) First we are splitting the string using String split() method and storing the substrings into a String array.
2) Creating an ArrayList while passing the substring reference to it using Arrays.asList() method.

package com.beginnersbook.string;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class StringtoArrayList {
    public static void main(String args[]){
        String num = "22,33,44,55,66,77";
        String str[] = num.split(",");
        
        List al = new ArrayList();
        al = Arrays.asList(str);
        for(String s: al){
            System.out.println(s);
        }
    }
}
Output:

22
33
44
55
66
77

asked Jun 11, 2015 in Java Interview Questions by rajesh
0 votes
70 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...