Logo

Programming-Idioms

Convert the string values from list a into a list of integers b.
Implementation
Java

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Java implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "strconv"
b := make([]int, len(a))
var err error
for i, s := range a {
	b[i], err = strconv.Atoi(s)
	if err != nil {
		return err
	}
}
uses classes, systutils, fgl;
var
  a: TStringList;
  b: specialize TList<Integer>;
...
for i := 0 to a.count-1 do b.add(IntToStr(a[i]));
b = a.map(&:to_i)
b = [int(elem) for elem in a]
let b: Vec<i64> = a.iter().map(|x| x.parse::<i64>().unwrap()).collect();
let b = a.map(Number)
integer, allocatable, dimension(:) :: b
  allocate (b(size(a)))
  read (unit=a,fmt=*) b
System.Linq;
var b = a.Select(i => int.Parse(i)).ToList();
@b = map { $_ += 0 } @a
let b: Vec<i32> = a.iter().flat_map(|s| s.parse().ok()).collect();
For i = LBound(a) To UBound(a)
    b(i) = CInt(a(i))
Next
var b = a.map(int.parse).toList();
import java.util.List;
import java.util.stream.Collectors;
List<Integer> b = items.stream()
                .map(Integer::parseInt)
                .collect(Collectors.toList());