zoukankan      html  css  js  c++  java
  • String类型的方法使用

    String.equals()方法源代码:

     public boolean equals(Object anObject) {
    
            if (this == anObject) {
    
                return true;
    
            }
    
            if (anObject instanceof String) {
    
                String anotherString = (String)anObject;
    
                int n = value.length;
    
                if (n == anotherString.value.length) {
    
                    char v1[] = value;
    
                    char v2[] = anotherString.value;
    
                    int i = 0;
    
                    while (n-- != 0) {
    
                        if (v1[i] != v2[i])
    
                            return false;
    
                        i++;
    
                    }
    
                    return true;
    
                }
    
            }
    
            return false;
    
    }
    

      

    String类方法的使用说明:

    1.int Length()

    返回字符串长度。

    2.char charAt(int n)

    返回指定索引处的char,索引范围为从0length() - 1. 3.getChars(int srcBegin,int srcEnd, char[] dst,int dstBegin)   

    获取从指定位置起的子串复制到字符数组中.要复制的第一个字符位于索引srcBegin处;要复制的最后一个字符位于索引srcEnd-1处(因此要制的字符总数是srcEnd-srcBegin)。要复制到dst子数组的字符从索引dstBegin处开始,并结束于索引.

     4.String replace(char oldChar,char newChar)子串替换:

    返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有oldChar得到的。如果oldChar在此String对象表示的字符序列中没有出现,则返回对此String对象的引用。否则,创建一个新的String对象,它所表示的字符序列除了所有的oldChar都被替换为newChar之外,与此String对象表示的字符序列相同。

    5.String toLowerCase():

    将此String中的所有字符都转换为小写

     

    6.String toUpperCase():

    将此String中的所有字符都转换为大写

     

    7.String trim()

     去除头尾空格:

     

    8.char[] toCharArray():

    将字符串对象转换为字符数组

  • 相关阅读:
    CSS3 --- 盒子
    CSS3 --- 伪元素
    CSS3 --- 伪类结构
    CSS3 --- 选择器
    HTML5 --- 新增表单属性
    HTML5 --- 新增标签
    CSS --- 定位
    CSS---浮动造成的影响
    CSS---盒子模型
    CSS---样式属性
  • 原文地址:https://www.cnblogs.com/ssyh/p/7729929.html
Copyright © 2011-2022 走看看