-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapDemo.java
More file actions
322 lines (275 loc) · 8.35 KB
/
mapDemo.java
File metadata and controls
322 lines (275 loc) · 8.35 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import java.util.*;
public class mapDemo {
public static void main(String[] args) {
// map
//Hashmap
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put((-1),"Tim");
hm.put(2,"Mary");
hm.put(3,"Catie");
System.out.println("\nThe elements of Hashmap are ");
/*
* for(Object x : arr)
*
*
*/
for(Map.Entry m:hm.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
//HashTable
Hashtable<Integer,String> ht=new Hashtable<Integer,String>();
ht.put(4,"Ales");
ht.put(5,"Rosy");
ht.put(6,"Jack");
ht.put(7,"John");
System.out.println("\nThe elements of HashTable are ");
for(Map.Entry n:ht.entrySet()){
System.out.println(n.getKey()+" "+n.getValue());
}
//TreeMap
TreeMap<Integer,String> map=new TreeMap<Integer,String>();
map.put(9,"Carlotte");
map.put(10,"Catie");
map.put(8,"Annie");
public class innerClassAssisted1 {
private String msg="Welcome to Java";
class Inner{
void hello(){
System.out.println(msg+", Let us start learning Inner Classes");
}
}
public static void main(String[] args) {
innerClassAssisted1 obj=new innerClassAssisted1();
innerClassAssisted1.Inner in=obj.new Inner();
in.hello();
}
}
public class innerClassAssisted2 {
private String msg="Inner Classes";//8
void display(){ //3
class Inner{
void msg(){//6
System.out.println(msg);//7
}
}
Inner l=new Inner(); //4
l.msg(); //5
}
public static void main(String[] args) {
innerClassAssisted2 ob=new innerClassAssisted2 (); //1
ob.display(); //2
}
}
//anonymous inner class
abstract class AnonymousInnerClass {
public abstract void display();
}
public class innerClassAssisted3 {
public static void main(String[] args) {
AnonymousInnerClass i = new AnonymousInnerClass() {
@Override
public void display() {
// TODO Auto-generated method stub
System.out.println("Inside anonymous inner class method");
}
};
i.display();
}
}
public class stringDemo {
public static void main(String[] args) {
//methods of strings
System.out.println("Methods of Strings");
//length
String sl=new String("Hello World");
System.out.println(sl.length());
//substring
String sub=new String("Welcome");
System.out.println(sub.substring(2));
//String Comparison
String s1="Hello";//ascii of l to be collected
String s2="Heldo";//ascii of d to be collected
//value of d will be subtracted from l
System.out.println(s1.compareTo(s2));//subtracted value
//IsEmpty
String s4="";
System.out.println(s4.isEmpty());
//toLowerCase
String s5="Hello";
System.out.println(s1.toLowerCase());
//replace
String s6="Heldo";
String replace=s2.replace('d', 'l');
System.out.println(replace);
//equals
String x="Welcome to Java";
String y="WeLcOmE tO JaVa";
System.out.println(x.equals(y));
System.out.println("\n");
System.out.println("Creating StringBuffer");
//Creating StringBuffer and append method
StringBuffer s=new StringBuffer("Welcome to Java!");
s.append("Enjoy your learning");
System.out.println(s);//Welcome to Java! Enjoy your learning
//insert method
s.insert(0, 'w');
System.out.println(s);
//replace method
StringBuffer sb=new StringBuffer("Hello");
sb.replace(0, 2, "hEl");
System.out.println(sb);
//delete method
sb.delete(0, 1);
System.out.println(sb);
//StringBuilder
System.out.println("\n");
System.out.println("Creating StringBuilder");
StringBuilder sb1=new StringBuilder("Happy");
sb1.app
//toLowerCase
String s5="Hello";
System.out.println(s1.toLowerCase());
//replace
String s6="Heldo";
String replace=s2.replace('d', 'l');
System.out.println(replace);
//equals
String x="Welcome to Java";
String y="WeLcOmE tO JaVa";
System.out.println(x.equals(y));
System.out.println("\n");
System.out.println("Creating StringBuffer");
//Creating StringBuffer and append method
StringBuffer s=new StringBuffer("Welcome to Java!");
s.append("Enjoy your learning");
System.out.println(s);//Welcome to Java! Enjoy your learning
//insert method
s.insert(0, 'w');
System.out.println(s);
//replace method
StringBuffer sb=new StringBuffer("Hello");
sb.replace(0, 2, "hEl");
System.out.println(sb);
//delete method
sb.delete(0, 1);
System.out.println(sb);
//StringBuilder
System.out.println("\n");
System.out.println("Creating StringBuilder");
StringBuilder sb1=new StringBuilder("Happy");
sb1.app
//conversion
System.out.println("\n");
System.out.println("Conversion of Strings to StringBuffer and StringBuilder");
String str = "Hello";
// conversion from String object to StringBuffer
StringBuffer sbr = new StringBuffer(str);
sbr.reverse();
System.out.println("String to StringBuffer");
System.out.println(sbr);
// conversion from String object to StringBuilder
StringBuilder sbl = new StringBuilder(str);
sbl.append("world");
System.out.println("String to StringBuilder");
System.out.println(sbl);
}
}
public class innerClassAssisted1 {
private String msg="Welcome to Java";
class Inner{
void hello(){
System.out.println(msg+", Let us start learning Inner Classes");
}
}
public static void main(String[] args) {
innerClassAssisted1 obj=new innerClassAssisted1();
innerClassAssisted1.Inner in=obj.new Inner();
in.hello();
}
}
public class innerClassAssisted2 {
private String msg="Inner Classes";//8
void display(){ //3
class Inner{
void msg(){//6
System.out.println(msg);//7
}
}
Inner l=new Inner(); //4
l.msg(); //5
}
public static void main(String[] args) {
innerClassAssisted2 ob=new innerClassAssisted2 (); //1
ob.display(); //2
}
}
//anonymous inner class
abstract class AnonymousInnerClass {
public abstract void display();
}
public class innerClassAssisted3 {
public static void main(String[] args) {
AnonymousInnerClass i = new AnonymousInnerClass() {
@Override
public void display() {
// TODO Auto-generated method stub
System.out.println("Inside anonymous inner class method");
}
};
i.display();
}
}
import java.util.*;
public class mapDemo {
public static void main(String[] args) {
// map
//Hashmap
HashMap<Integer,String> hm=new HashMap<Integer,String>();
hm.put((-1),"Tim");
hm.put(2,"Mary");
hm.put(3,"Catie");
System.out.println("\nThe elements of Hashmap are ");
/*
* for(Object x : arr)
*
*
*/
for(Map.Entry m:hm.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
//HashTable
Hashtable<Integer,String> ht=new Hashtable<Integer,String>();
ht.put(4,"Ales");
ht.put(5,"Rosy");
ht.put(6,"Jack");
ht.put(7,"John");
System.out.println("\nThe elements of HashTable are ");
for(Map.Entry n:ht.entrySet()){
System.out.println(n.getKey()+" "+n.getValue());
}
//TreeMap
TreeMap<Integer,String> map=new TreeMap<Integer,String>();
map.put(9,"Carlotte");
map.put(10,"Catie");
map.put(8,"Annie");
//conversion
System.out.println("\n");
System.out.println("Conversion of Strings to StringBuffer and StringBuilder");
String str = "Hello";
// conversion from String object to StringBuffer
StringBuffer sbr = new StringBuffer(str);
sbr.reverse();
System.out.println("String to StringBuffer");
System.out.println(sbr);
// conversion from String object to StringBuilder
StringBuilder sbl = new StringBuilder(str);
sbl.append("world");
System.out.println("String to StringBuilder");
System.out.println(sbl);
}
}
1. Complete all the self learning videos
2. Go through all the built in methods inside the collections
3. Go through all the built in methods inside the String class
4. Go through all the built in methods inside the StringBuffer class
5. Go through all the built in methods inside the StringBuilder class