How to convert a String without separator to an ArrayList
.
My String is like this:
String str = \"abcd...\"
If you dn not need to modify list after it created, probably the better way would be to wrap string into class implementing List<Character>
interface like this:
import java.util.AbstractList;
import java.util.List;
public class StringCharacterList extends AbstractList <Character>
{
private final String string;
public StringCharacterList (String string)
{
this.string = string;
}
@Override
public Character get (int index)
{
return Character.valueOf (string.charAt (index));
}
@Override
public int size ()
{
return string.length ();
}
}
And then use this class like this:
List <Character> l = new StringCharacterList ("Hello, World!");
System.out.println (l);