java源码之Arrays.toString()和Arrays.deepToString()

 

/**
 * 数组转化成字符串
 * <p>
 * Returns a string representation of the contents of the specified array.
 * If the array contains other arrays as elements, they are converted to
 * strings by the {@link Object#toString} method inherited from
 * <tt>Object</tt>, which describes their <i>identities</i> rather than
 * their contents.
 * <p>
 * 返回指定数组的字符串,
 * 如果数组包含其他数组作为元素,那么这些元素将执行继承自Object的toString方法,getClass().getName() + "@" Integer.toHexString(hashCode())的方式,而不是它们的内容。
 *
 * <p>
 * The value returned by this method is equal to the value that would
 * be returned by <tt>Arrays.asList(a).toString()</tt>, unless <tt>a</tt>
 * is <tt>null</tt>, in which case <tt>"null"</tt> is returned.
 * <p>
 * 该方法的返回值将和Arrays.asList(a).toString()方法返回值相同,除非a==null,这时方法的返回值是字符串"null",而后者返回null.
 *
 * @param a the array whose string representation to return
 * @return a string representation of <tt>a</tt>
 * @see #deepToString(Object[])
 * @since 1.5
 */
public static String toString(Object[] a) {
    if (a == null)
        return "null";

    // 不用length==0来判断空数组,因为下面的代码需要用到length-1
    int iMax = a.length - 1;
    if (iMax ==
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值