import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.stream.*;
class Java8ConversionExamples
{
{
//1 Convert `List<String>` to `List<Integer>`
List
<String
> l1
= Arrays.
asList("1",
"2",
"3"); List
<Integer
> r1
= l1.
stream().
map(Integer::parseInt
).
collect(Collectors.
toList()); System.
out.
println("1: " + r1
);
//2 Convert `List<String>` to `int[]`
int[] r2
= l1.
stream().
mapToInt(Integer::parseInt
).
toArray();
//3 Convert `String[]` to `List<Integer>`
String[] a1
= {"4",
"5",
"6"}; List
<Integer
> r3
= Stream.
of(a1
).
map(Integer::parseInt
).
collect(Collectors.
toList()); System.
out.
println("3: " + r3
);
//4 Convert `String[]` to `int[]`
int[] r4
= Stream.
of(a1
).
mapToInt(Integer::parseInt
).
toArray();
//5 Convert `String[]` to `List<Double>`
List
<Double
> r5
= Stream.
of(a1
).
map(Double::parseDouble
).
collect(Collectors.
toList()); System.
out.
println("5: " + r5
);
//6 (bonus) Convert `int[]` to `String[]`
int[] a2 = {7, 8, 9};
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLio7CgpjbGFzcyBKYXZhOENvbnZlcnNpb25FeGFtcGxlcwp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQkvLzEgQ29udmVydCBgTGlzdDxTdHJpbmc+YCB0byBgTGlzdDxJbnRlZ2VyPmAKCQlMaXN0PFN0cmluZz4gbDEgPSBBcnJheXMuYXNMaXN0KCIxIiwgIjIiLCAiMyIpOwoJCUxpc3Q8SW50ZWdlcj4gcjEgPSBsMS5zdHJlYW0oKS5tYXAoSW50ZWdlcjo6cGFyc2VJbnQpLmNvbGxlY3QoQ29sbGVjdG9ycy50b0xpc3QoKSk7CgkJU3lzdGVtLm91dC5wcmludGxuKCIxO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