String小结

栏目: Java · 发布时间: 8年前

内容简介:String小结

String应该是用得最多的一个类型,不管是之前使用了无数次也好,又不管是看过源码也好,还是有些坑要注意

总结

String#getBytes()

getBytes得到的是地址,所以对同一个Stirng调用getBytes得到的内容是不同的

@Test
 public void getBytesTest(){
 String s = "123456";
 System.out.println(s.getBytes()); //[B@61e717c2
 System.out.println(s.getBytes()); //[B@66cd51c3
 System.out.println(s.getBytes()); //[B@4dcbadb4
 }

String#equals()

虽然String的equals()接受的是Object对象,但是如果想要返回true,传入的也必须是equals对象,同理,Integer之类也有类似情况

@Test
 public void equalsTest(){
 String str = "1234";
 Integer integer = 1234;
 System.out.println(str.equals(integer));//false
 }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Coding the Matrix

Coding the Matrix

Philip N. Klein / Newtonian Press / 2013-7-26 / $35.00

An engaging introduction to vectors and matrices and the algorithms that operate on them, intended for the student who knows how to program. Mathematical concepts and computational problems are motiva......一起来看看 《Coding the Matrix》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具