Computer scienceProgramming languagesJavaWorking with dataCollectionsCollections framework

The Map interface

Theory

How many entries?

Report a typo

Implement method log. Print output depending on size: Too many objects if size is greater than 1, Something in the map if size is exactly 1 and There are no objects if map is empty.

Sample Input 1:

3

Sample Output 1:

Too many objects
Write a program in Java 17
import java.util.*;

class Main {
private static void log(Map<Long, String> map) {
// implement me
}

// do not change the code below
public static void main(String[] args) {
String valueBase = "value-";
Scanner scanner = new Scanner(System.in);

Map<Long, String> m = new HashMap<>();
long size = scanner.nextLong();
for (long i = 0; i < size; ++i) {
Long key = i;
String value = valueBase + i;
m.put(key, value);
}
log(Map.copyOf(m));
}
}
___

Create a free account to access the full topic