zoukankan      html  css  js  c++  java
  • String类

    1.String是什么?String是字符串。
    2.特点:1.字符串不变:字符串的值在创建后不能被更改。2. 因为String对象是不可变的,所以它们可以被共享。3."abc" 等效于 char[] data={ 'a' , 'b' , 'c' } 。
    3.构造方法:public String() :初始化新创建的 String对象,以使其表示空字符序列。 public String(char[] value) :通过当前参数中的字符数组来构造新的String。
    public String(byte[] bytes) :通过使用平台的默认字符集解码当前参数中的字节数组来构造新的String
    4.常用方法:equals (Object anObject):将此字符串与指定对象进行比较。equalsIgnoreCase (String anotherString) :将此字符串与指定对象进行比较,忽略大小写
    length () :返回此字符串的长度。 concat(String str) :将指定的字符串连接到该字符串的末尾。
    charAt (int index) :返回指定索引处的 char值。indexOf (String str) :返回指定子字符串第一次出现在该字符串内的索引。
    substring (int beginIndex) :返回一个子字符串,从beginIndex开始截取字符串到字符 串结尾。
    substring (int beginIndex, int endIndex) :返回一个子字符串,从beginIndex到 endIndex截取字符串。含beginIndex,不含endIndex。
    toCharArray () :将此字符串转换为新的字符数组. replace (CharSequence target, CharSequence replacement) :将与target匹配的字符串使 用replacement字符串替换。
    split(String regex):分割。 touppercase():大写 tolowercase():小写
    5.注意事项:1.如果直接使用=进行赋值,会在常量池中找是否有该对象,如果有则直接赋值,没有则会创建。
    2.如果是使用new关键字对象,则在内存中开辟一段内存空间并设置值。
    3.对于引用类型来说比较的是地址值;对于基本类型来说比较的是数值

    好文要顶 已关注 收藏该文

  • 相关阅读:
    LeetCode 461. Hamming Distance
    LeetCode 442. Find All Duplicates in an Array
    LeetCode 448. Find All Numbers Disappeared in an Array
    LeetCode Find the Difference
    LeetCode 415. Add Strings
    LeetCode 445. Add Two Numbers II
    LeetCode 438. Find All Anagrams in a String
    LeetCode 463. Island Perimeter
    LeetCode 362. Design Hit Counter
    LeetCode 359. Logger Rate Limiter
  • 原文地址:https://www.cnblogs.com/Ran0707-0721/p/13954566.html
Copyright © 2011-2022 走看看