首页 > 其他 > 详细

jdk源码_String(1)

时间:2020-05-11 22:21:26      阅读:44      评论:0      收藏:0      [点我收藏+]
package com.example.demo;

public class Sort {
    //java源码之string
    public static void main(String[] args) {
        {//空字符对象创建字符串
            String s = new String();
            System.out.println(s);
        }

        {
            //字符串对象创建字符串
            String s = new String("a");
            System.out.println(s);
        }
        {
            //字符数组方式声明字符串
            char[] c = {a, b, c};
            String s = new String(c);
            System.out.println(s);
        }
        {
            /**
             *  // Note: offset or count might be near -1>>>1.
             if (offset > value.length - count) {
             throw new StringIndexOutOfBoundsException(offset + count);
             意思是
             -1>>>1 相当于 integer.maxvalue()
             如果offset + count > value.length 可能会溢出
             而 offset > value.length - count 则不会
             >>>代表无符号又移
             整数源反补都一样
             负数源码第一位是符号位
             负数反码 符号位不变,参照源码其他位按位取反
             符数补码 符号位不变 参照源码 按位取反 末位加一

             }
             */
            //截取字符串
            char[] a = {a, d, f, r, d, e};
            String s = new String(a, 2, 4);
            System.out.println(s);
        }

    }
}

 

jdk源码_String(1)

原文:https://www.cnblogs.com/xiaoshahai/p/12872448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!