美文网首页
比较运算符和equals

比较运算符和equals

作者: 哈迪斯Java | 来源:发表于2021-11-03 09:53 被阅读0次
    image.png

    package HspLearningPoly.poly01;

    public class ObjPerson {
    public static void main(String[] args) {
    Person person1 = new Person();
    person1.name = "yang";

        Person person2 = new Person();
        person2.name = "yang";
    
        System.out.println(person1 == person2);
        System.out.println(person1.name.equals(person2.name));
        System.out.println(person1.equals(person2));
    
        String s1 = new String("abs");
        String s2 = new String("abs");
    
        System.out.println(s1.equals(s2));
        System.out.println(s1 == s2);
    
    }
    

    }

    class Person {
    public String name;
    }
    false
    true
    false
    true
    false

    相关文章

      网友评论

          本文标题:比较运算符和equals

          本文链接:https://www.haomeiwen.com/subject/jjmqzltx.html