public class Main {
public static void main(String[] args){
String one = "one";
String two = "two";// 来 自 n o w j a v a . c o m
String var1 = "one";
String var2 = "Two";
String pieceone = "o";
String piecetwo = "ne";
if (one.equals(var1)){
System.out.println ("String one equals var1 using equals");
}
/*
来自
*nowjava.com*/
if (one.equals(two)){
System.out.println ("String one equals two using equals");
}
if (two.equals(var2)){
System.out.println ("String two equals var2 using equals");
}
if (one == var1){
System.out.println ("String one equals var1 using ==");
}
if (two.equalsIgnoreCase(var2)){
System.out.println ("String two equals var2 using equalsIgnoreCase");
}
System.out.println("Trying to use == on Strings that are pieced together");
String piecedTogether = pieceone + piecetwo;
if (one.equals(piecedTogether)){
System.out.println("The strings contain the same value using equals");
}
if (one == piecedTogether) {
System.out.println("The string contain the same value using == ");
}
if (one.compareTo(var1) == 0){
System.out.println("One is equal to var1 using compareTo()");
}
System.out.println("Comparision Using regionMatches");
String sentence = "Java 8 is great!";
String matchStr = "great";
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。