字符串相等(==)的全测试
来源:互联网 发布:怎么在淘宝卖原味丝袜 编辑:程序博客网 时间:2024/05/12 14:48
- package p1;
- /**
- * 字符串相等(==)的全测试。
- *
- * @author XT Zang,老紫竹
- */
- class TestString1 {
- public static void main(String[] args) {
- String hello = "Hello", lo = "lo";
- System.out.print((hello == "Hello") + " "); // true
- System.out.print((Other.hello == hello) + " "); // true
- System.out.print((p2.Other.hello == hello) + " "); // true
- System.out.print((hello == ("Hel" + "lo")) + " "); // true
- System.out.print((hello == ("Hel" + lo)) + " "); // false
- System.out.println(hello == ("Hel" + lo).intern()); // true
- }
- }
- class Other {
- static String hello = "Hello";
- }
- package p2;
- public class Other {
- public static String hello = "Hello";
- }
This example illustrates six points:
Literal strings within the same class (§8) in the same package (§7) represent references to the same String object (§4.3.1).相同包,相同类的字符串常量指向相同的字符串对象
Literal strings within different classes in the same package represent references to the same String object.相同包,不相同类的字符串常量指向相同的字符串对象
Literal strings within different classes in different packages likewise represent references to the same String object.不同包,不同类的字符串常量指向相同的字符串对象
Strings computed by constant expressions (§15.28) are computed at compile time and then treated as if they were literals.字符串在编译期间可以连接起来的,视同一个常量字符串
Strings computed by concatenation at run time are newly created and therefore distinct.
The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
参考地址:http://blog.csdn.net/ZangXT/archive/2008/10/11/3057471.aspx
- 字符串相等(==)的全测试
- Java中字符串相等的测试
- 测试字符串是否相等的方法
- 测试字符串是否相等
- 字符串的相等比较
- 计算字符串中相等的!
- 字符串的内容是否相等
- Java判断字符串相等的办法(不能直接用==判断)
- js用==比较两个相等的字符串时,报错
- Objective-C中 ==、isEqual、isEqualToString判断字符串相等
- 中英文字符串显示相等长度的函数
- ORACLE中字符串是否相等的比较
- Java 中字符串相等的注意点
- 两个字符串相等的布尔值
- struts 2字符串相等的判断
- c#比较两个字符串相等的方法。
- 字符串的相等性和不可变性
- C#中判断字符串相等的方法
- 设计模式笔记(三)—— 策略模式
- CodeGear RAD Studio 2009正式RTM简化绿色中文版 V12.0.3170.16989
- 输入框测试考虑侧重点
- C#3.0新体验(四)匿名类型
- 简单入门正则表达式 - 第五章 多字符的匹配
- 字符串相等(==)的全测试
- C#3.0新体验(五)Lambda表达式
- 百度和谷歌的搜索对比
- log4j.properties配置文件
- 跟踪邮件
- 新版.Net开发必备十大工具
- 解决url地址中含有中文乱码问题
- VC6中使用内存DC加载并显示JPG图片的注意事项
- /n与/r的区别!