java字符串

字符串比较

在java中“==”是用来比较地址值是否相同

如过想用字符串比较请用以下方法:

 

 eg:

public class helloWord{
    public static void main(String[] args) {
        String a="ABc";
        String b=new String("abC");
     //比较地址
     System.out.println(a==b);
     //完全一致
        boolean c=a.equals(b);
        System.out.println(c);

     //忽略大小写
boolean d=a.equalsIgnoreCase(b); System.out.println(d); } }
结果:

  false
  false
  true

 

 

 

posted @ 2022-05-19 14:17  欧阳锦涛  阅读(27)  评论(0)    收藏  举报
TOP 底部