// 13. charAt()
public class CharAtExample {
public static void main(String[] args) {
String str = "Hello, World!";
char character = str.charAt(4);
System.out.println("Character at index 4: " + character);
}
}// 14. toCharArray()
public class ToCharArrayExample {
public static void main(String[] args) {
String str = "Hello, World!";
char[] charArray = str.toCharArray();
System.out.println("Character array: " + Arrays.toString(charArray));
}
}// 15. split()
public class SplitExample {
public static void main(String[] args) {
String str = "Hello, World!";
String[] parts = str.split(", ");
System.out.println("Split string: " + Arrays.toString(parts));
}
}// 16. concat()
public class ConcatExample {
public static void main(String[] args) {
String str1 = "Hello, ";
String str2 = "World!";
String concatenatedString = str1.concat(str2);
System.out.println("Concatenated string: " + concatenatedString);
}
}// 17. equalsIgnoreCase()
public class EqualsIgnoreCaseExample {
public static void main(String[] args) {
String str1 = "hello";
String str2 = "HELLO";
boolean isEqualIgnoreCase = str1.equalsIgnoreCase(str2);
System.out.println("Are strings equal ignoring case? " + isEqualIgnoreCase);
}
}// 18. lastIndexOf()
public class LastIndexOfExample {
public static void main(String[] args) {
String str = "Hello, World!";
int lastIndex = str.lastIndexOf('o');
System.out.println("Last index of 'o': " + lastIndex);
}
}// 19. substring(int beginIndex, int endIndex)
public class SubstringWithIndicesExample {
public static void main(String[] args) {
String str = "Hello, World!";
String substring = str.substring(7, 12);
System.out.println("Substring from index 7 to 12: " + substring);
}
}// 20. replaceAll()
public class ReplaceAllExample {
public static void main(String[] args) {
String str = "Hello, World!";
String replacedString = str.replaceAll("[aeiou]", "*");
System.out.println("String after replacement: " + replacedString);
}
}// 21. matches()
public class MatchesExample {
public static void main(String[] args) {
String str = "Hello, World!";
boolean matches = str.matches("^[a-zA-Z0-9]*$");
System.out.println("Matches the pattern? " + matches);
}
}// 22. valueOf()
public class ValueOfExample {
public static void main(String[] args) {
int number = 42;
String convertedNumber = String.valueOf(number);
System.out.println("Converted number to string: " + convertedNumber);
}
}// 23. codePointAt()
public class CodePointAtExample {
public static void main(String[] args) {
String str = "Hello";
int codePoint = str.codePointAt(1);
System.out.println("Code point at index 1: " + codePoint);
}
}// 24. codePointBefore()
public class CodePointBeforeExample {
public static void main(String[] args) {
String str = "Hello";
int codePoint = str.codePointBefore(3);
System.out.println("Code point before index 3: " + codePoint);
}
}// 25. codePointCount()
public class CodePointCountExample {
public static void main(String[] args) {
String str = "Hello, World!";
int codePoints = str.codePointCount(0, str.length());
System.out.println("Number of Unicode code points: " + codePoints);
}
}// 26. offsetByCodePoints()
public class OffsetByCodePointsExample {
public static void main(String[] args) {
String str = "Hello, World!";
int index = str.offsetByCodePoints(0, 7);
System.out.println("Index after moving 7 code points forward: " + index);
}
}// 27. intern()
public class InternExample {
public static void main(String[] args) {
String str1 = new String("Hello");
String str2 = str1.intern();
System.out.println("Interned string: " + str2);
}
}// 28. strip()
public class StripExample {
public static void main(String[] args) {
String str = " Hello, World! ";
String strippedString = str.strip();
System.out.println("Stripped string: '" + strippedString + "'");
}
}// 29. repeat()
public class RepeatExample {
public static void main(String[] args) {
String str = "Hello! ";
String repeatedString = str.repeat(3);
System.out.println("Repeated string: " + repeatedString);
}
}// 30. lines()
public class LinesExample {
public static void main(String[] args) {
String str = "Hello\nWorld\nWelcome";
String[] lines = str.lines().toArray(String[]::new);
System.out.println("Individual lines:");
for (String line : lines) {
System.out.println(line);
}
}
}// 31. stripLeading()
public class StripLeadingExample {
public static void main(String[] args) {
String str = " Hello, World! ";
String strippedString = str.stripLeading();
System.out.println("Leading stripped string: '" + strippedString + "'");
}
}// 32. stripTrailing()
public class StripTrailingExample {
public static void main(String[] args) {
String str = " Hello, World! ";
String strippedString = str.stripTrailing();
System.out.println("Trailing stripped string: '" + strippedString + "'");
}
}// 33. isBlank()
public class IsBlankExample {
public static void main(String[] args) {
String str = " ";
boolean isBlank = str.isBlank();
System.out.println("Is the string blank? " + isBlank);
}
}