Convert List<String> to List<Integer> directly

Solution 1:

Using Java8:

stringList.stream().map(Integer::parseInt).collect(Collectors.toList());

Solution 2:

No, you need to loop over the array

for(String s : strList) intList.add(Integer.valueOf(s));

Solution 3:

Using lambda:

strList.stream().map(org.apache.commons.lang3.math.NumberUtils::toInt).collect(Collectors.toList());

Solution 4:

Guava Converters do the trick.

import com.google.common.base.Splitter;
import com.google.common.primitives.Longs;

final Iterable<Long> longIds = 
    Longs.stringConverter().convertAll(
        Splitter.on(',').trimResults().omitEmptyStrings()
            .splitToList("1,2,3"));