Skip to content

Commit fe57df0

Browse files
author
Araf Karsh Hamid
committed
Added Java 12 Examples
1 parent e2e5cdb commit fe57df0

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

src/java11/StringUtilsExample.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) 2024 Araf Karsh Hamid
3+
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
11+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17+
* THE SOFTWARE.
18+
19+
* This program and the accompanying materials are dual-licensed under
20+
* either the terms of the Eclipse Public License v1.0 as published by
21+
* the Eclipse Foundation
22+
23+
* or (per the licensee's choosing)
24+
25+
* under the terms of the Apache 2 License version 2.0
26+
* as published by the Apache Software Foundation.
27+
*/
28+
package java11;
29+
30+
import java.io.IOException;
31+
import java.nio.file.Files;
32+
import java.nio.file.Path;
33+
import java.nio.file.Paths;
34+
35+
/**
36+
* Java 11 Example
37+
* String Utils Example
38+
*
39+
* @author: Araf Karsh Hamid
40+
* @version:
41+
* @date:
42+
*/
43+
public class StringUtilsExample {
44+
45+
public static void main (String[] args) {
46+
// Java 11
47+
System.out.println("JAVA 11 >>>>>--------------------------------------------------------");
48+
System.out.println(">> String Utils Blank Test --------------------------------------------");
49+
String emptyString = " ";
50+
System.out.println("String Var emptyString=["+emptyString+"] isBlank = "+emptyString.isBlank());
51+
52+
System.out.println(">> String Utils Strip Test --------------------------------------------");
53+
String planet = " Saturn ";
54+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.strip()+"]");
55+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.stripLeading()+"] >> Leading");
56+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.stripTrailing()+"] >> Trailing");
57+
58+
System.out.println(">> String Utils Lines Test --------------------------------------------");
59+
String multiLineData = "This is the 1st Line.\nThis is Line 2.\nThis is Line 3.\nThis is Line 4.\nThis is the last Line.\n";
60+
multiLineData.lines().forEach(System.out::println);
61+
}
62+
}

src/java12/StringUtilsExample.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (c) 2024 Araf Karsh Hamid
3+
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
11+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17+
* THE SOFTWARE.
18+
19+
* This program and the accompanying materials are dual-licensed under
20+
* either the terms of the Eclipse Public License v1.0 as published by
21+
* the Eclipse Foundation
22+
23+
* or (per the licensee's choosing)
24+
25+
* under the terms of the Apache 2 License version 2.0
26+
* as published by the Apache Software Foundation.
27+
*/
28+
package java12;
29+
30+
/**
31+
* Java 11,12 Example
32+
* String Utils Example
33+
*
34+
* @author: Araf Karsh Hamid
35+
* @version:
36+
* @date:
37+
*/
38+
public class StringUtilsExample {
39+
40+
public static void main (String[] args) {
41+
// Java 11
42+
System.out.println("JAVA 11 >>>>>--------------------------------------------------------");
43+
System.out.println(">> String Utils Blank Test --------------------------------------------");
44+
String emptyString = " ";
45+
System.out.println("String Var emptyString=["+emptyString+"] isBlank = "+emptyString.isBlank());
46+
47+
System.out.println(">> String Utils Strip Test --------------------------------------------");
48+
String planet = " Saturn ";
49+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.strip()+"]");
50+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.stripLeading()+"] >> Leading");
51+
System.out.println("String var planet=["+planet+"] After Strip planet=["+planet.stripTrailing()+"] >> Trailing");
52+
53+
System.out.println(">> String Utils Lines Test --------------------------------------------");
54+
String multiLineData = "This is the 1st Line.\nThis is Line 2.\nThis is Line 3.\nThis is Line 4.\nThis is the last Line.\n";
55+
multiLineData.lines().forEach(System.out::println);
56+
57+
// Java 12
58+
System.out.println("JAVA 12 >>>>>--------------------------------------------------------");
59+
System.out.println(">> String Utils Formatted String");
60+
String data = "My Name is %s. I am the youngest doctor (age %d) at %s Hospital.".formatted("Jane Doe", 23, "John Hopkins");
61+
System.out.println(data);
62+
System.out.println(">> String Utils Transform String");
63+
String word = "Sword";
64+
System.out.println("String var word=[" + word + "] After Transform=["
65+
+ word.transform(s -> s.substring(1, 2).toUpperCase() + s.substring(2, 5)) + "]");
66+
}
67+
}

0 commit comments

Comments
 (0)