-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.java
More file actions
103 lines (77 loc) · 3.28 KB
/
example.java
File metadata and controls
103 lines (77 loc) · 3.28 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
import java.util.*;
public class example {
public static void main(String[] args) {
/**
* String
*/
String s1 = "Hello", s2 = "hello";
System.out.println(s1.compareToIgnoreCase(s2));
System.out.println(s1.compareTo(s2)); // H < h
s1 = "Look, look!";
boolean b1, b2, b3;
b1 = s1.regionMatches(6, "Look", 0, 4);
b2 = s1.regionMatches(true, 6, "Look", 0, 4);
// s1.regionMatches(ignoreCase = true, start = 0, other = "Hello", otherStart = 5, len = 5);
System.out.println("b1 = " + b1);
System.out.println("b2 = " + b2);
System.out.println("hello startWith he: " + s2.startsWith("he", 0));
System.out.println("h | ello startWith he: " + s2.startsWith("he", 1));
s1 = "simon";
s2 = "simon";
System.out.println("s1 hashcode: " + s1.hashCode());
System.out.println("s2 hashcode: " + s1.hashCode());
System.out.println("s1 intern: " + s1.intern()); // from String unique pool, faster than compare content
System.out.println("s2 intern: " + s2.intern());
s1 = s2.replace("si", "XXX");
System.out.println("XXXmon: " + s1);
s1 = "2021 10 01";
s2 = s1.replace(" ", "-");
System.out.println("2021-10-01: " + s2);
s2 = s2.replaceAll("\\d", "X");
System.out.println("XXXX-XX-XX: " + s2);
char[] charArray = {'S', 'I', 'M', 'O', 'N'};
String simon = new String(charArray);
System.out.println("SIMON: " + simon);
String mon = new String(charArray, 2, 3);
System.out.println("MON: " + mon);
String now = new java.util.Date().toString();
System.out.println("time: " + now);
StringBuilder sb = new StringBuilder();
sb.append("Helen and Simon ").append("Love together!");
sb.replace(0, 5, "Simon");
System.out.println("Simon and Simon ..." + sb.toString());
sb.delete(12, 16);
System.out.println(sb.toString());
System.out.println("capacity: " + sb.capacity());
System.out.println("length: " + sb.length());
System.out.println(new Double(1.007).compareTo(1.00700001));
var s = "hello";
// System.out.println(s.substring(6)); out of bound
/**
* TreeMap
*/
/*
TreeMap<Integer, String> treemap = new TreeMap<>();
treemap.put(3, "val");
treemap.put(2, "val");
treemap.put(1, "val");
treemap.put(5, "val");
treemap.put(4, "val");
System.out.println(treemap.keySet().toString());
TreeMap<Integer, String> reverseMap = new TreeMap<>(Comparator.reverseOrder());
reverseMap.put(3, "val");
reverseMap.put(2, "val");
reverseMap.put(1, "val");
reverseMap.put(5, "val");
reverseMap.put(4, "val");
System.out.println(reverseMap.keySet().toString());
Integer highestKey = treemap.lastKey();
Integer lowestKey = treemap.firstKey();
System.out.println(highestKey + " " + lowestKey);
System.out.println(treemap.ceilingKey(10)); // >10 smallest
System.out.println(treemap.floorKey(10)); // <10 largest
int i = Integer.parseInt("0001");
System.out.println(i);
*/
}
}