Palpable Coral
Palpable Coral

Reputation: 105

Make string into arraylist with individual characters Java

I have a String called new_alpha which contains only characters (no whitespace). How do I split it so that each character is a different element in a new ArrayList?

Upvotes: 0

Views: 68

Answers (2)

joshiii
joshiii

Reputation: 1

int len=new_alpha.length();
ArrayList<Character> arr=new ArrayList<Character>();
for(int i=0;i<len;i++)
{ arr.add(new_alpha.charAt(i));
}

Your all character of String convert into ArrayList;

Upvotes: 0

Qingfei Yuan
Qingfei Yuan

Reputation: 1212

Arrays.asList(new_alpha.toCharArray())

Upvotes: 1

Related Questions