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
 }

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

查看所有标签

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

PHP and MySQL Web Development (3rd Edition) (Developer's Library

PHP and MySQL Web Development (3rd Edition) (Developer's Library

Luke Welling、Laura Thomson / Sams / 2004-09-29 / USD 49.99

We've taken the best and made it even better. The third edition of the best-selling PHP and MySQL Web Development has been updated to include material and code on MySQL 5, PHP 5 and on PHPs object mod......一起来看看 《PHP and MySQL Web Development (3rd Edition) (Developer's Library》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具