21
loading...
This website collects cookies to deliver better user experience
public class Test {
public static void main(String []args)
{
String str = "This is a test string";
System.out.println("The length of the String is : " + str.length());
}
}
There is this one length method also there in java. This method is used to find out the length of an array in java.
public class DemoArray {
public static void main(String []args)
{
int[] arr = new int[69];
System.out.println("The length of the array is : " + arr.length);
}
}
You can run your code online here
public class Demo {
public static void main(String []args) {
String str1="";
String str2="This is a test string";
System.out.println("This is for str1 : " + str1.isEmpty());
System.out.println("This is for str2 : " + str2.isEmpty());
}
}
There is this method isBlank(), this method is similar to isEmpty() but additionally checks for whitespace in the given String. This method was introduced in Java 11.
public class Demo {
public static void main(String []args) {
String str = "this complete string was in lower case";
String subStr = str.toUpperCase();
System.out.println(subStr);
}
}
There is this method toLowerCase() which is used to convert the given string into lower-case.
public class Demo {
public static void main(String []args) {
String str = "THIS COMPLETE STRING WAS IN UPPER CASE";
String subStr = str.toLowerCase();
System.out.println(subStr);
}
}
public class Demo {
public static void main(String []args) {
String str = "First string";
System.out.println(str.equals("First string"));
}
}
There are several other methods to compare in Java, I'll write about those in a separate article.
public class Demo {
public static void main(String []args) {
String str = "To find index of character at 15th index in the string";
char result = str.charAt(15);
System.out.println("Character at 15th index is : " + result);
}
}