Select your group/channel/service
t.me/Sid_info/69
t.me/Sid_info/69
// 1. length()
public class StringLengthExample {
public static void main(String[] args) {
String str = "Hello, World!";
int length = str.length();
System.out.println("Length of the string: " + length);
}
}👍1
// 2. toUpperCase()
public class UpperCaseExample {
public static void main(String[] args) {
String str = "Hello, World!";
String upperCaseString = str.toUpperCase();
System.out.println("Uppercase string: " + upperCaseString);
}
}// 3. toLowerCase()
public class LowerCaseExample {
public static void main(String[] args) {
String str = "Hello, World!";
String lowerCaseString = str.toLowerCase();
System.out.println("Lowercase string: " + lowerCaseString);
}
}// 4. equals()
public class StringEqualityExample {
public static void main(String[] args) {
String str1 = "hello";
String str2 = "HELLO";
boolean isEqual = str1.equals(str2);
System.out.println("Are strings equal? " + isEqual);
}
}// 5. substring()
public class SubstringExample {
public static void main(String[] args) {
String str = "Hello, World!";
String substring = str.substring(7);
System.out.println("Substring from index 7: " + substring);
}
}// 6. indexOf()
public class IndexOfExample {
public static void main(String[] args) {
String str = "Hello, World!";
int index = str.indexOf('o');
System.out.println("Index of 'o': " + index);
}
}👍1
// 7. replace()
public class ReplaceExample {
public static void main(String[] args) {
String str = "Hello, World!";
String replacedString = str.replace('l', 'z');
System.out.println("String after replacement: " + replacedString);
}
}❤1
// 8. contains()
public class ContainsExample {
public static void main(String[] args) {
String str = "Hello, World!";
boolean contains = str.contains("World");
System.out.println("Does the string contain 'World'? " + contains);
}
}// 9. trim()
public class TrimExample {
public static void main(String[] args) {
String spacedString = " Some spaces ";
String trimmedString = spacedString.trim();
System.out.println("Trimmed string: '" + trimmedString + "'");
}
}// 10. isEmpty()
public class IsEmptyExample {
public static void main(String[] args) {
String emptyString = "";
boolean isEmpty = emptyString.isEmpty();
System.out.println("Is the string empty? " + isEmpty);
}
}// 11. startsWith()
public class StartsWithExample {
public static void main(String[] args) {
String str = "Hello, World!";
boolean startsWith = str.startsWith("Hello");
System.out.println("Does the string start with 'Hello'? " + startsWith);
}
}// 12. endsWith()
public class EndsWithExample {
public static void main(String[] args) {
String str = "Hello, World!";
boolean endsWith = str.endsWith("World!");
System.out.println("Does the string end with 'World!'? " + endsWith);
}
}👍1
// 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);
}
}