zoukankan      html  css  js  c++  java
  • jdk源码_String(1)

    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);
            }
    
        }
    }
  • 相关阅读:
    SQL高级应用
    li元素之间产生间隔
    js array
    js高阶函数汇总
    git学习记录
    static和assets的区别
    router-link
    vue 创建项目 create和init
    vue的store状态管理模式
    vue中的各种属性
  • 原文地址:https://www.cnblogs.com/xiaoshahai/p/12872448.html
Copyright © 2011-2022 走看看