Reputation: 1601
i am learning about collection from this site
Where the guy gave the example
import java.util.HashMap;
import java.util.Map;
public class MapTester {
public static void main(String[] args) {
// keys are Strings
// objects are also Strings
Map<String, String> map = new HashMap<>();
fillData(map);
// write to command line
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
// add and remove from the map
map.put("iPhone", "Created by Apple");
map.remove("Android");
// write again to command line
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
}
private static void fillData(Map<String, String> map) {
map.put("Android", "Mobile");
map.put("Eclipse IDE", "Java");
map.put("Eclipse RCP", "Java");
map.put("Git", "Version control system");
}
}
although in above program i can understand that k and v variable are undefined or not present locally.
map.forEach((k, v) -> System.out.printf("%s %s%n", k, v));
and facing the issue with same line.
Please help me learning the collections.
Upvotes: 1
Views: 187
Reputation: 1601
Answer of this question
You need to be using 4.4 (Luna) to get Java 8 support.
Might be useful for someone who checked it later.
Thanks @greg-449
Upvotes: 0
Reputation: 2534
It is working fine on my system. Can you check are you using JDK8? Lamdas support introduced in JAVA 8. You can test java version by using java --version
.
Upvotes: 0