Senior
//list of car license plates, numbers are always of a standard type // need to output each number separately to the console // then create a map of the number - its digits (example A123BC:123) where the key is A123BC and the value is 123 //var autoNumbers = List.of(List.of("A123BC", "B421FT"), List.of("O543EC", "B421FT", "I2220A"));
sobes.tech AI
Answer from AI
To solve the task in Java, you can iterate over nested lists, print each number to the console, and then create a Map where the key is the car number, and the value is only the digits from the number.
Example code:
import java.util.*;
import java.util.stream.*;
public class AutoNumbers {
public static void main(String[] args) {
List<List<String>> autoNumbers = List.of(
List.of("A123BC", "B421FT"),
List.of("O543EC", "B421FT", "I2220A")
);
Map<String, String> numberMap = new HashMap<>();
for (List<String> sublist : autoNumbers) {
for (String number : sublist) {
System.out.println(number);
// Extract digits from the number
String digits = number.replaceAll("\\D", "");
numberMap.put(number, digits);
}
}
// Example output of the map
numberMap.forEach((key, value) -> System.out.println(key + ":" + value));
}
}
Here, replaceAll("\\D", "") removes all non-digit characters, leaving only the digits.