• [javaSE笔记5]String


    java.lang.String类

    程序当中所有的双引号字符串, 都是String类的对象

    字符串是常量 , 内容是永不可变的

    由于字符串不可改变, 所以字符串是可以共享使用的

    创建字符串的常见方式

    public String(); 创建一个空白字符串, 不含有任何内容

    public String(char[] array) ; 根据字符数组的内容来创建对应的字符串

    public String(byte[] array) ; 根据字节数组的呢欸容来创建对应的字符串

    e.g.

    1592880833714

    1592880845775

    字符串常量池

    1592881476916

    常用方法

    内容比较

    1. equal方法 : 根据内容进行比较 ( ==是根据地址 )
    2. equalsIgnoreCase : 忽略大小写进行内容比较

    获取

    1. public int length()

    2. public String concat(String str)

    3. public char charAt(int index) : 获取指定索引位置的单个字符

    4. public int indexOf(String str) : 查找参数字符串在本字符串当中首次出现的索引位置, 如果没有则返回-1值

    截取

    1. public String substring (int index) : 截取从index处一直到字符串末尾的字符串
    2. public String substring (int begin, int end) : 左闭右开截取新字符串

    转换

    1. public char[] toCharArray() : 将当前字符串拆分为字符串数组作为返回值
    2. public byte[] getBytes() : 获得当前字符串底层的字节数组
    3. public String replace (CharSequence oldString, CharSequence newString) : 将所有出现的老字符串替换成为新字符串

    分割

    1. public String[] split (String regex) : 按照参数的规则( 正则表达式 ), 将字符串切分为若干部分;
  • 相关阅读:
    WCF Server Console
    Restart IIS With Powershell
    RestartService (recursively)
    Copy Files
    Stopping and Starting Dependent Services
    多线程同步控制 ManualResetEvent AutoResetEvent MSDN
    DTD 简介
    Using Powershell to Copy Files to Remote Computers
    Starting and Stopping Services (IIS 6.0)
    java中的NAN和INFINITY
  • 原文地址:https://www.cnblogs.com/roccoshi/p/13182256.html
Copyright © 2020-2023  润新知