为什么不一样

wdllove 2002-11-22 04:12:18
String sicp_id="90";
byte icpp_id[]=sicp_id.getBytes();
System.out.println(icpp_id);
//输出icpp_id
byte icp_id[] = new byte[10];//ÉèÖÃicp_id
icp_id[0] =0x39;
icp_id[1] =0x30;
icp_id[2] =0;
System.out.println(icp_id);
//输出icp_id

为什么输出的结果不一样
...全文
27 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fastmask 2002-11-22
  • 打赏
  • 举报
回复
看一下Object的实现就明白了。如下:
/**
* Returns a string representation of the object. In general, the
* <code>toString</code> method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read.
* It is recommended that all subclasses override this method.
* <p>
* The <code>toString</code> method for class <code>Object</code>
* returns a string consisting of the name of the class of which the
* object is an instance, the at-sign character `<code>@</code>', and
* the unsigned hexadecimal representation of the hash code of the
* object. In other words, this method returns a string equal to the
* value of:
* <blockquote>
* <pre>
* getClass().getName() + '@' + Integer.toHexString(hashCode())
* </pre></blockquote>
*
* @return a string representation of the object.
*/
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
wdllove 2002-11-22
  • 打赏
  • 举报
回复
哪们能提供一个说明byte的网址.
DaimonJ 2002-11-22
  • 打赏
  • 举报
回复
眼花
study_body 2002-11-22
  • 打赏
  • 举报
回复
你实际上调用的是
System.out.println(icp_id.toString())实际上toString方法是从Object继承过来的,如果想知道为什么不同看Object.toSting();如果想让他们相同,自己编写一个toString.
flash007 2002-11-22
  • 打赏
  • 举报
回复
当然不一样,你这样输出的根本不是icpp_id和icp_id的值,你输出的是JVM分配给他们的一个地址引用的值,而不是实际的值,你引用icpp_id[0]和icp_id[0],输出的结构就一样了。

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧