-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collection.java
117 lines (108 loc) · 3.34 KB
/
Collection.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Collection
{
static Map<String, List<String>> map1 = new HashMap<String, List<String>>();
static Map<String,Integer> map2 = new HashMap<String,Integer>();
public void add_in_map1(String key, List<String> values)
{
map1.put(key, values);
System.out.println(map1);
}
public void delete_in_map1(String key)
{
map1.remove(key);
System.out.println(map1);
}
public void findFaculties(String key)
{
if(map1.containsKey(key))
{
List<Integer> faculties = new ArrayList<Integer>();
List<String> list = map1.get(key);
Set<String> keys = map2.keySet();
for(String l:list)
{
for(String k:keys)
{
if(l.equals(k))
{
faculties.add(map2.get(k));
}
}
}
System.out.println(faculties);
}
else
System.out.println("No such student");
}
public static void main(String[] args)
{
List<String> valSetOne = new ArrayList<String>();
valSetOne.add("Python");
valSetOne.add("Maths");
valSetOne.add("C");
List<String> valSetTwo = new ArrayList<String>();
valSetTwo.add("C");
valSetTwo.add("C++");
List<String> valSetThree = new ArrayList<String>();
valSetThree.add("C++");
valSetThree.add("Physics");
valSetThree.add("Chemistry");
map1.put("A", valSetOne);
map1.put("B", valSetTwo);
map1.put("C", valSetThree);
map2.put("Python", 111);
map2.put("Maths", 222);
map2.put("C", 333);
map2.put("C++", 444);
map2.put("Physics", 555);
map2.put("Chemistry", 666);
System.out.println("Fetching Keys and corresponding [Multiple] Values:\n");
for (Map.Entry<String, List<String>> entry1 : map1.entrySet())
{
String key1 = entry1.getKey();
List<String> values1 = entry1.getValue();
System.out.println("Key = " + key1);
System.out.println("Values = " + values1);
}
System.out.println("Fetching Keys and corresponding [Single] Values: \n");
for (Map.Entry<String,Integer> entry2 : map2.entrySet())
{
String key2 = entry2.getKey();
Integer values2 = entry2.getValue();
System.out.println("Key = " + key2);
System.out.println("Values = " + values2);
}
System.out.println("enter choice:");
{
Scanner sc = new Scanner(System.in);
int choice=sc.nextInt();
switch(choice)
{
case 1:
Collection c1 = new Collection();
List<String> val = new ArrayList<String>();
val.add("HPC");
val.add("CS");
val.add("DSA");
c1.add_in_map1("D",val);
break;
case 2:
Collection c2 = new Collection();
c2.delete_in_map1("B");
break;
case 3:
Collection c3 = new Collection();
c3.findFaculties("E");
break;
default:
System.out.println("error");
}
}
}
}