java判断字符串相等的方法
作者:sy793314598 时间:2023-05-19 14:08:30
java中的字符串比较竟然不能直接用”==”!!!!而要用equals(),返回true为两字符串相等,返回false为两字符串不相等,举个栗子:
if (s1.equals(s2)) {
System.out.println("s1与s2相等!!");
} else {
System.out.println("s1与s2没啥关系!!");
}
1、字符串是对象类型,所以不能用简单的“==”判断
2、equals()比较的是对象的内容(区分字母的大小写格式)是否相等
3、“==”比较两个对象时,比较的是两个对象的内存地址,所以不相等
来源:https://blog.csdn.net/sy793314598/article/details/76212150
标签:java,判断,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C# 禁用鼠标中间键的方法
2022-01-24 04:17:24
C#基于DBContext(EF)实现通用增删改查的REST方法实例
2021-06-23 20:56:07
Spring注解与P/C命名空间超详细解析
2022-08-04 19:42:34
AndroidStudio 使用过程中出现的异常(Gradle sync failed)处理办法
2022-03-18 21:46:43
Java之策略模式比较器案例讲解
2021-12-25 22:24:32
java.lang.ExceptionInInitializerError异常的解决方法
2023-01-13 04:23:16
wenserver获取天气预报数据实例分享
2021-07-22 14:22:52
SpringMVC源码解读之HandlerMapping - AbstractUrlHandlerMapping系列request分发
2022-07-26 20:39:48
jar包手动添加到本地maven仓库的步骤详解
2023-11-23 05:09:37
![](https://img.aspxhome.com/file/2023/5/59785_0s.png)
C#重写DataGridView
2021-06-09 11:56:26
Java SWT中常见弹出框实例总结
2023-08-22 00:42:22
![](https://img.aspxhome.com/file/2023/9/93349_0s.png)
elasticsearch head的安装及使用过程解析
2021-10-10 10:24:59
![](https://img.aspxhome.com/file/2023/2/79942_0s.png)
SpringBoot中使用Servlet三大组件的方法(Servlet、Filter、Listener)
2021-07-19 18:41:43
![](https://img.aspxhome.com/file/2023/3/104703_0s.png)
Android studio设计简易计算器
2023-01-26 22:21:40
![](https://img.aspxhome.com/file/2023/2/138282_0s.jpg)
C++中关键字Struct和Class的区别
2022-12-23 11:25:06
C语言实现代码雨效果
2021-11-26 18:11:20
![](https://img.aspxhome.com/file/2023/7/127557_0s.gif)
详解Spring MVC 集成EHCache缓存
2022-05-28 04:42:52
![](https://img.aspxhome.com/file/2023/3/77933_0s.png)
Java实现驼峰、下划线互转的方法
2023-08-18 09:17:54
Spring整合MyBatis图示过程解析
2023-11-13 11:45:09
![](https://img.aspxhome.com/file/2023/8/59188_0s.png)
Java CompletableFuture 异步超时实现深入研究
2022-12-28 04:18:14