在Java中,可以使用equals()
方法来比较两个字符串的内容是否相同。示例如下:
String str1 = "Hello";
String str2 = "hello";
if(str1.equals(str2)){
System.out.println("两个字符串相同");
}else{
System.out.println("两个字符串不同");
}
另外,如果需要忽略大小写比较两个字符串,可以使用equalsIgnoreCase()
方法:
String str1 = "Hello";
String str2 = "hello";
if(str1.equalsIgnoreCase(str2)){
System.out.println("两个字符串相同");
}else{
System.out.println("两个字符串不同");
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/981578.html