-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
64 lines (47 loc) · 1.54 KB
/
Test.java
File metadata and controls
64 lines (47 loc) · 1.54 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
package com.interview.all;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args) {
// input JAVA_WORLD
// output Java World
String str = "JAVA_WORLD";
String strArr = str.replace("_", " ");
String s1[] = strArr.split(" ");
if (s1[0].startsWith("J") && s1[1].startsWith("W")) {
String s = s1[0];
String sss = s.replace("JAVA", "Java") + " ";
String ss = s1[1];
String ssss = ss.replace("WORLD", "World");
//System.out.print(sss+ssss);
}
// or we can use
for (int i = 0; i < s1.length; i++) {
if (s1[i].startsWith("J")) {
String s = s1[i];
//System.out.print(s.replace("JAVA", "Java") + " ");
}
if (s1[i].startsWith("W")) {
String s = s1[i];
//System.out.print(s.replace("WORLD", "World"));
}
}
//-----------------------------------------------
HashMap<Integer, String> hashMap = new HashMap<Integer,String>();
hashMap.put(2, "dev");
hashMap.put(7, "qa");
hashMap.put(1, "pod");
hashMap.put(5, "uat");
List<Map.Entry<Integer, String>> list = new LinkedList<Map.Entry<Integer, String>>(hashMap.entrySet());
Collections.sort(list,(i1,i2)->i1.getValue().compareTo(i2.getValue()));
HashMap<Integer, String> map = new LinkedHashMap<Integer,String>();
for(Map.Entry<Integer, String> entry:list) {
map.put(entry.getKey(), entry.getValue());
}
map.forEach((k,v)->{System.out.println(k+" "+v);});
}
}