Cannot reproduce. Your code when copy-pasted works as you intended; no empty first element.
When working character-by-character, better to use Unicode code points. Each of the 143,859 characters defined in Unicode is assigned a number, called a code point, from zero to just over a million.
Get a IntStream
of these integer code point numbers, in the form of a sequence of int
primitive values.
IntStream codePointStream = "love".codePoints();
Capture those numbers to a list. Convert from primitive int
to object Integer
.
List < Integer > codePoints = codePointStream.boxed().toList();
codePoints.toString(): [108, 111, 118, 101, 128152]
Map those to a list of single-character String
objects, to get back to the characters. Call Character.toString( codePoint )
to generate the text.
List < String > characters = codePoints.stream().map( Character :: toString ).toList();
characters = [l, o, v, e, ]
We could combine those.
List < String > characters =
"love"
.codePoints()
.mapToObj( Character :: toString )
.toList();
characters = [l, o, v, e, ]
Before Java 16, replace .toList()
with the more verbose .collect( Collectors.toList() )
.