-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapProgram.java
More file actions
51 lines (42 loc) · 1.99 KB
/
MapProgram.java
File metadata and controls
51 lines (42 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.dj;
import java.util.HashMap;
import java.util.Map;
public class MapProgram {
public static void main(String[] args) {
Map<String, String> languages = new HashMap<>();
if(languages.containsKey("Java")) {
System.out.println("Java already exists");
} else {
languages.put("Java", "a compiled high level, object-oriented, platform independent language");
System.out.println("Java added successfully");
}
languages.put("Python","an interpreted, object-oriented, high-level programming language with dynamic semantics");
languages.put("Algol", "an algorithmic language");
System.out.println(languages.put("BASIC", "Beginners All Purposes Symbolic Instruction Code"));
System.out.println(languages.put("Lisp", "Therein lies madness"));
// System.out.println(languages.get("Java"));
if (languages.containsKey("Java")){
System.out.println("Java is already in the map");
}else {
languages.put("Java", "this course is about Java");
}
System.out.println("====================================");
// languages.remove("Lisp");
if(languages.remove("Algol", "an algorithmic language")) {
System.out.println("Algol removed");
}else {
System.out.println("Algol not removed, key/value pair not found");
}
if (languages.replace("Lisp", "Therein lies madness", "a functional programming language with imperative features")){
System.out.println("Lisp replaced");
}else {
System.out.println("Lisp was not replaced");
}
// System.out.println(languages.replace("Scala", "this will not be added"));
for (String key: languages.keySet()){
System.out.println(key + " : " + languages.get(key));
}
// System.out.println(languages.put("Java", "this course is about Java"));
// System.out.println(languages.get("Java"));
}
}