Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public class stringtowords
{
public static void main(String args[])
{
String s="hello! my name@ is pragya";
String wo[]=s.split(" ");
for(String w:wo)
{
System.out.println(w);
}
String word;
for(int i=0;i<wo.length;i++)
{ word=wo[i].toLowerCase();

List<character> li=new ArrayList<character>();
for (char ch:word.toCharArray())
if(ch>='a' && ch<='z')
li.add(ch);
//for(char ch:li)
String ss=li.toString();
System.out.println(ss);

}
}
}

What I have tried:

I'm trying toString() to convert it into String but it's not working.
Posted
Updated 12-Sep-18 10:38am

As far as I know, you have to iterate over list items. Try
Java
public static void main(String arg[])
{
  List<Character> lc = new ArrayList<Character>();
  lc.add('p');
  lc.add('r');
  lc.add('a');
  lc.add('g');
  lc.add('y');
  lc.add('a');

  StringBuilder sb = new StringBuilder();

  for (Character c : lc)
    sb.append(c.charValue());

  String s = sb.toString();

  System.out.println(s);
}
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900