public class Main {
public static void main(String[] args) {
// Example test data
Map<String, List<Double>> lists = new HashMap<>();
// Add data
lists.put("A", Arrays.asList(1.0, 2.0, 3.0));
lists.put("B", Arrays.asList(4.0, 5.0));
lists.put("C", Arrays.asList(6.0, 7.0, 8.0, 9.0));
lists.put("D", Arrays.asList(10.0));
System.out.println(lists.entrySet());
Set<Map.Entry<String, List<Double>>> entrySet = lists.entrySet();
if (!entrySet.isEmpty()) {
// Using iterator
Iterator<Map.Entry<String, List<Double>>> iterator = entrySet.iterator();
Map.Entry<String, List<Double>> firstEntry = iterator.next();
List<Double> valueOfFirstEntry = firstEntry.getValue();
System.out.println("Value of the first entry: " + valueOfFirstEntry);
} else {
System.out.println("Map is empty");
}
// Print the test data
for (Map.Entry<String, List<Double>> entry : lists.entrySet()) {
String key = entry.getKey();
List<Double> values = entry.getValue();
System.out.println("Key: " + key + ", Values: " + values);
}
}
}
Main.main(null);
[A=[1.0, 2.0, 3.0], B=[4.0, 5.0], C=[6.0, 7.0, 8.0, 9.0], D=[10.0]]
Value of the first entry: [1.0, 2.0, 3.0]
Key: A, Values: [1.0, 2.0, 3.0]
Key: B, Values: [4.0, 5.0]
Key: C, Values: [6.0, 7.0, 8.0, 9.0]
Key: D, Values: [10.0]