Java equals() 方法

Java 教程 · 2019-02-08 10:27:18

equals() 方法用于判断 Number 对象与方法的参数进是否相等。

语法

public boolean equals(Object o)

参数

o -- 任何对象。

返回值

如 Number 对象不为 Null,且与方法的参数类型与数值都相等返回 True,否则返回 False。

Double 和 Float 对象还有一些额外的条件,可以参阅 API 手册:JDK 1.6

实例

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));
    }
}

编译以上程序,输出结果为:

false
true
false

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

An Introduction to Probability Theory and Its Applications

An Introduction to Probability Theory and Its Applications

William Feller / Wiley / 1991-1-1 / USD 120.00

Major changes in this edition include the substitution of probabilistic arguments for combinatorial artifices, and the addition of new sections on branching processes, Markov chains, and the De Moivre......一起来看看 《An Introduction to Probability Theory and Its Applications》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具