S
Sharp
Hi
I have a sting that contains long stretches of whitespaces between
characters.
For example:
String str = " A B C
";
I would like to include all the characters including the white spaces into a
data structure (e.g., ArrayList).
The code I have written is something like this:
List list = new ArrayList();
for (int i=0; i<str.length(); i++)
{
list.add(str.charAt(i));
}
Unfortunately it just adds "ABC" into the array list.
It seems charAt() method ignores whitespaces,
But the documentation doesn't mention anything about whitespaces.
Iam happy to add another character in place of the whitespace,
So I tried using the replaceAll() method from the string class, but that
didn't work.
Any advice will be appreciated.
Cheers
Sharp
I have a sting that contains long stretches of whitespaces between
characters.
For example:
String str = " A B C
";
I would like to include all the characters including the white spaces into a
data structure (e.g., ArrayList).
The code I have written is something like this:
List list = new ArrayList();
for (int i=0; i<str.length(); i++)
{
list.add(str.charAt(i));
}
Unfortunately it just adds "ABC" into the array list.
It seems charAt() method ignores whitespaces,
But the documentation doesn't mention anything about whitespaces.
Iam happy to add another character in place of the whitespace,
So I tried using the replaceAll() method from the string class, but that
didn't work.
Any advice will be appreciated.
Cheers
Sharp