您的位置 首页 java

java中字符串不等于怎么判断

java中字符串不等于可以使用equals()方法判断,equals()方法用于将字符串与指定的对象比较。

语法

public boolean equals(Object anObject)

参数

anObject — 与字符串进行比较的对象。

返回值

如果给定对象与字符串相等,则返回 true;否则返回 false。

实例

public class Test {    public static void main(String args[]) {        String Str1 = new String("runoob");        String Str2 = Str1;        String Str3 = new String("runoob");        boolean retVal;        retVal = Str1.equals( Str2 );        System.out.println("返回值 = " + retVal );        retVal = Str1.equals( Str3 );        System.out.println("返回值 = " + retVal );    }}

以上程序执行结果为:

返回值 = true

返回值 = true

文章来源:智云一二三科技

文章标题:java中字符串不等于怎么判断

文章地址:https://www.zhihuclub.com/15409.shtml

关于作者: 智云科技

热门文章

网站地图