Skip to content

Commit 95b2e03

Browse files
committed
Deep dive on String in Java
1 parent d1c0dd8 commit 95b2e03

24 files changed

Lines changed: 428 additions & 0 deletions

section6/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

section6/src/ChangeCaseDemo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class ChangeCaseDemo {
2+
3+
public static void main(String[] args) {
4+
String originalString = "Java";
5+
String upperCaseString = originalString.toUpperCase();
6+
String lowerCaseString = originalString.toLowerCase();
7+
String specialString = "Java1@Best";
8+
String specialUpperCaseString = specialString.toUpperCase();
9+
String specialLowerCaseString = specialString.toLowerCase();
10+
}
11+
12+
}

section6/src/CharAtMethodDemo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class CharAtMethodDemo {
2+
3+
public static void main(String[] args) {
4+
String java = "JAVA";
5+
char j = java.charAt(0);
6+
char exception = java.charAt(4);
7+
}
8+
9+
}

section6/src/ConcatMethodDemo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class ConcatMethodDemo {
2+
3+
public static void main(String[] args) {
4+
String hello = "Hello";
5+
hello = hello + " " + "World";
6+
System.out.println(hello);
7+
8+
String hello1 = "Hello";
9+
hello1 = hello1.concat(" ").concat("World");
10+
System.out.println(hello1);
11+
12+
String emptyString = "";
13+
String nullString = null;
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class ConvertStringDemo {
2+
3+
public static void main(String[] args) {
4+
int intValue = 42;
5+
double doubleValue = 3.14;
6+
boolean boolValue = true;
7+
8+
String str1 = String.valueOf(intValue);
9+
String str2 = String.valueOf(doubleValue);
10+
String str3 = String.valueOf(boolValue);
11+
String str4 = String.valueOf('M');
12+
13+
int age = 30;
14+
String message = "My age is : "+ age;
15+
String piValue = ""+ 3.14;
16+
}
17+
}

section6/src/EmptyCheckDemo.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class EmptyCheckDemo {
2+
3+
public static void main(String[] args) {
4+
String myString = "";
5+
boolean isEmpty = myString.isEmpty();
6+
boolean isLengthZero = myString.length()==0;
7+
boolean isEqualEmpty = "".equals(myString);
8+
9+
String nullString = null;
10+
boolean isnullEmpty = "".equals(nullString);
11+
// boolean isEmptyNull = nullString.length()==0;
12+
String blankString = " ";
13+
boolean isBlankEmpty = blankString.isEmpty();
14+
boolean isBlank = blankString.isBlank();
15+
}
16+
17+
}

section6/src/EscapeSeqDemo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class EscapeSeqDemo {
2+
3+
public static void main(String[] args) {
4+
String name = "\"Madan\"";
5+
System.out.println(name);
6+
7+
String m = "\u004D";
8+
System.out.println(m);
9+
String unicodeName = "\u004Dadan\u0021";
10+
System.out.println(unicodeName);
11+
}
12+
13+
}

section6/src/InternMethodDemo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class InternMethodDemo {
2+
3+
public static void main(String[] args) {
4+
String hello = "Hello";
5+
String obj = new String("Hello").intern();
6+
System.out.println(hello==obj);
7+
8+
String s1 = "hello";
9+
String s2 = new String("hello");
10+
System.out.println(s1==s2);
11+
String s3 = s2.intern();
12+
System.out.println(s1==s3);
13+
}
14+
15+
}

section6/src/LengthMethodDemo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class LengthMethodDemo {
2+
3+
public static void main(String[] args) {
4+
String str1 = "Hello";
5+
String str2 = "World";
6+
String combined = str1+ " "+str2;
7+
8+
int length1 = str1.length();
9+
int length2 = str2.length();
10+
int length3 = combined.length();
11+
12+
int emptyLength = "".length();
13+
int length4 = "Hello".length();
14+
}
15+
}

section6/src/PalindromeDemo.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Class helps to identify a given String is
3+
* a palindrome or not.
4+
*
5+
* <p>
6+
* Examples of palindromes are,
7+
* <ul>
8+
* <li>madam</li>
9+
* <li>racecar</li>
10+
* <li>mom</li>
11+
* <li>noon</li>
12+
* <li>wow</li>
13+
* </ul>
14+
* </p>
15+
*
16+
*/
17+
public class PalindromeDemo {
18+
public static void main(String[] args) {
19+
String input = "mom";
20+
StringBuffer stringBuffer = new StringBuffer(input);
21+
boolean isPalindrome = input.equals(stringBuffer.reverse().toString());
22+
System.out.printf("Is the given String %s is a palindrome or not ? : %b%n", input, isPalindrome);
23+
String textBlock = """
24+
""";
25+
}
26+
}

0 commit comments

Comments
 (0)