demo1 equals equalsIgnoreCase
String strA = "mldn";
String strB = "MLDN";
System.out.println(strA.equals(strB));
System.out.println(strA.equalsIgnoreCase(strB));// 不区分大小写来比较
demo2 compareTo 字符串大小比较,compareToIgnoreCase
- 这个方法很重要,返回结果 正数,0,负数
public class HelloWorld {
public static void main(String args[]){// String args[]字符串数组的意思
String strA = "m";
String strB = "M";
System.out.println(strA.compareTo(strB));// 32
System.out.println(strB.compareTo(strA));// -32
System.out.println("Hello".compareTo("Hello"));//0
System.out.println(strA.compareToIgnoreCase(strB));// 0 不计较大小写,结果一样的;
}
}
标签:7.11,System,println,字符串,strB,strA,out,比较,String
From: https://www.cnblogs.com/pansidong/p/17461930.html