Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials", str2 = "point";
// comparing str1 and str2
int retval = str1.compareTo(str2);
// prints the return value of the comparison
if (retval < 0) {
System.out.println("str1 is greater than str2");
}
else if (retval == 0) {
System.out.println("str1 is equal to str2");
}
else {
System.out.println("str1 is less than str2");
}
}
}
public class Test {
public static void main(String args[]) {
Integer x = 5;
Integer y = 10;
Integer z =5;
Short a = 5;
System.out.println(x.equals(y));
System.out.println(x.equals(z));
System.out.println(x.equals(a));
}
}
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("tuts ");
System.out.println("buffer = " + buff);
// appends the char argument as string to the string buffer.
buff.append('A');
// print the string buffer after appending
System.out.println("After append = " + buff);
buff = new StringBuffer("abcd ");
System.out.println("buffer = " + buff);
// appends the char argument as string to the string buffer.
buff.append('!');
// print the string buffer after appending
System.out.println("After append = " + buff);
}
}
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials", str2 = "point";
// comparing str1 and str2
int retval = str1.compareTo(str2);
System.out.println(str1==str2);
// prints the return value of the comparison
if (retval < 0) {
System.out.println("str1 is greater than str2");
} else if (retval == 0) {
System.out.println("str1 is equal to str2");
} else {
System.out.println("str1 is less than str2");
}
}
}
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
// converts all upper case letters in to lower case letters
String str1 = "SELF LEARNING CENTER";
System.out.println("string value = " + str1.toLowerCase());
str1 = "TUTORIALS POINT";
System.out.println("string value = " + str1.toLowerCase());
// converts all lower case letters in to upper case letters
String str2 = "This is TutorialsPoint";
System.out.println("string value = " + str2.toUpperCase());
str2 = "www.tutorialspoint.com";
System.out.println("string value = " + str2.toUpperCase());
}
}
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
// string with leading and trailing white space
String str = " This is TutorialsPoint ";
System.out.print("Before trim = ");
System.out.println(".." + str + "..");
// leading and trailing white space removed
System.out.print("After trim = ");
System.out.println(".." + str.trim() + "..");
}
}