java中字符串的比较
2015-01-03 23:20
405 查看
public class StringCompareTest { public static void main(String[] args){ String s1 = "Hello"; String s2 = "Hello"; // assert pass, because both s1 and s2 point to the same const object. assert s1 == s2; String s3 = new String("World!"); String s4 = new String("World!"); // AssertionError, because s3 and s4 are different object // assert s3 == s4; assert s3 != s4; // assert pass, equals are used to compare the contents of two strings. assert s3.equals(s4); String s5 = new String(""); // AssertionError, don't examine an empty string with '==' // assert s5 == ""; } }
编译:
javac StringCompareTest.java
运行:
java -ea StringCompareTest,
-ea表示启用断言 (enable assertion),java虚拟机默认是关闭断言的。
相关文章推荐
- Java中的字符串比较
- java(例子006)字符串比较
- java 字符串比较
- java 字符串比较
- toCharArray()方法 和 Java中比较两个字符串是否相等equals方法
- Java中字符串比较的注意点
- Java 判断字符串是否为空的三种方法性能比较
- 在JAVA中的字符串比较
- java中字符串比较
- JAVA和C#字符串常用方法的比较
- Java字符串的比较(收藏)
- java中字符串的比较,必须使用string1.equals(string2)来进行判断
- Java中字符串的比较
- java中XML格式的字符串4读取方式的简单比较
- Java 5种字符串拼接方式性能比较
- java中字符串比较为什么不能用“==”
- Java 5种字符串拼接方式性能比较
- 字符串比较问题(java)
- JAVA简单实现不区分大小写以及空格比较字符串
- java中字符串链接性能比较