黑马程序员技术交流社区

标题: 字符串的面试题 [打印本页]

作者: 蓝光四号    时间: 2016-10-11 23:33
标题: 字符串的面试题

        (4)字符串的面试题(看程序写结果)
                A:==和equals()
                        String s1 = new String("hello");
                        String s2 = new String("hello");
                        System.out.println(s1 == s2);// false
                        System.out.println(s1.equals(s2));// true

                        String s3 = new String("hello");
                        String s4 = "hello";
                        System.out.println(s3 == s4);// false
                        System.out.println(s3.equals(s4));// true

                        String s5 = "hello";
                        String s6 = "hello";
                        System.out.println(s5 == s6);// true
                        System.out.println(s5.equals(s6));// true
                B:字符串的拼接
                        String s1 = "hello";
                        String s2 = "world";
                        String s3 = "helloworld";
                        System.out.println(s3 == s1 + s2);// false
                        System.out.println(s3.equals((s1 + s2)));// true

作者: z443863517    时间: 2016-10-12 08:30
这里就是考察的字符串这种数据类型的一旦赋值就不能改变的属性。和不同情况下内存储存位置

作者: Zzh94520    时间: 2016-10-12 14:48
。。。。。。。。。。
作者: Jarc    时间: 2016-10-12 23:06
明白字符串的创建就明白了
作者: 顺其自然吧    时间: 2016-10-12 23:13
为了黑马币,各种溜达,面熟不要奇怪!!!{:2_32:}
作者: 18600071691    时间: 2016-10-12 23:19
还没学到着呢
作者: huangweicong    时间: 2016-10-12 23:28
赞!!!!!!!!!!!!!1
作者: GXM    时间: 2016-10-13 00:09
明天讲`````````
作者: 杨杰锋    时间: 2016-10-14 10:14
明白字符串的创建就明白了
作者: zhaokun1114    时间: 2016-10-14 11:58
可以的  好好看下
作者: Bast1an    时间: 2016-10-15 13:22
常用api那个视频里讲的挺清楚的,楼主可以看看

作者: Array先生    时间: 2016-10-15 14:12
== 比较基本类型比较的是值,比较引用类型比较的是地址值,如果重写toString()方法的话equals比较的是值
作者: 读书可以当饭吃    时间: 2016-10-15 14:39
比较地址值的题很常见了,留个心眼就好
作者: barny    时间: 2016-10-15 20:33
这个不是太难
作者: 海苔    时间: 2016-10-16 23:50
.==比较的是地址值吗?那equals是不是重写了,比较的是内容?






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2