-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMethods.java
More file actions
44 lines (31 loc) · 1.47 KB
/
StringMethods.java
File metadata and controls
44 lines (31 loc) · 1.47 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
public class StringMethods {
public static void main(String[] args) {
String birthDate = "25/11/1982";
int startingIndex = birthDate.indexOf("1982");
System.out.println("startingIndex = " + startingIndex);
System.out.println("Birth year = " + birthDate.substring(startingIndex));
System.out.println("Month = " + birthDate.substring(3,5));
String newDate = String.join("/", "25","11","1982");
System.out.println("newDate = "+ newDate);
newDate = "25";
newDate = newDate.concat("/");
newDate = newDate.concat("11");
newDate = newDate.concat("/");
newDate = newDate.concat("1982");
System.out.println("newDate = " + newDate);
newDate = "25" + "/" + "11" + "/" + "1982";
System.out.println("newDate = " + newDate);
newDate = "25".concat("/").concat("11").concat("/".concat("1982"));
System.out.println("newDate = " + newDate);
System.out.println(newDate.replace('/','-'));
System.out.println(newDate.replace("2","00"));
System.out.println(newDate.replaceFirst("/","-"));
System.out.println(newDate.replaceAll("/","---"));
System.out.println("ABC\n".repeat(3));
System.out.println("-".repeat(20));
System.out.println("ABC\n".repeat(3).indent(8));
System.out.println("-".repeat(20));
System.out.println(" ABC\n".repeat(3).indent(-2));
System.out.println("-".repeat(20));
}
}