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
Recommended Answers
Jump to Postehm... It is missing?
You are the only one who knows what your code is supposed to do, and what it is doing, so you are the only one who can say what is wrong with it.
As for your add method: there isn't any.
Please be specific about what …
Jump to PostThe explanation of what goes wrong when you call add there is in my previous reply.
You are passing a List to a parameter that can on take a String as parameter.
All 5 Replies
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.