I have got an easy task to draw three int values. Then build a new int value from the highest digits from drawn values. Is there an easy way to convert an Int to List of Integers? I want to resolve this by streams but I need a List of Integers created from drawn value to find maxValue digit.
For example: 123, 256, 189 = 369
I have done this in a naive way, I'm still learning and start wondering if is an easier and more code efficient way.
public static List<Integer> convertingValue(int value) {
List<Integer> intList = new ArrayList<>();
char[] arr = String.valueOf(value).toCharArray();
for (int i = 0; i < arr.length; i++) {
intList.add(Character.getNumericValue(arr[i]));
}
return intList;
}
public static void main(String[] args) {
IntSupplier is = () -> new Random().nextInt(999 - 100 + 1) + 100;
List<Integer> figuresList =
List.of(is.getAsInt(), is.getAsInt(), is.getAsInt());
var list = figuresList
.stream()
.map(Basic02::convertingValue)
.map(x -> x.stream().mapToInt(v -> v)
.max().orElseThrow(NoSuchElementException::new))
.collect(Collectors.toList());
System.out.println(list);
}