import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class Counter
{
public void split(String a,ArrayList<String> al)
{
char ch[]=a.toCharArray();
int p=0;
for(int i=0;i<ch.length;i++)
{
if(ch[i]==32)
{List<String> l=al.subList(p,i);
ArrayList<String> al1=new ArrayList<String>(l);
//String str=new String[al1.size()];
//al1.toArray(str);
//al1.add(str);
//al1.add(al1);
//why this is also wrong al1.add(al.sublist(p,i));
p=i;
System.out.println(al1);
}
}
}
public static void main(String... s)
{
String k="My name is Khan Khan";
List<String> l=Arrays.asList(k);
ArrayList<String> al=new ArrayList<String>(l);
Counter c=new Counter();
c.split(k,al);
System.out.println(k);
}
}
Ankit_18 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
Ankit_18 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
Ankit_18 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.