zoukankan      html  css  js  c++  java
  • 动手动脑以及String类函数总结

    1.动手动脑

    public class StringEquals { 
    public static void main(String[] args) { 
    String s1=new String("Hello");
    String s2=new String("Hello");
    System.out.println(s1==s2);
    System.out.println(s1.equals(s2));
    String s3="Hello";
    String s4="Hello";
    System.out.println(s3==s4);
    System.out.println(s3.equals(s4));
    }
    }

    2.String类函数说明

    Length():

    参数:无

    返回值:调用此方法的字符串的长度(int)

    charAt() :

    方法用于返回指定索引处的字符,索引范围为从 0 到 length() - 1。

    返回值:返回指定索引处的字符

    getChars():

    void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin):

    将字符从此字符串复制到目标字符数组。

    参数:

    srcBegin -- 字符串中要复制的第一个字符的索引。

    srcEnd -- 字符串中要复制的最后一个字符之后的索引。

    dst -- 目标数组。

    dstBegin -- 目标数组中的起始偏移量。

    replace():

    String replace(char oldChar, char newChar)

    replace() 方法通过用 newChar 字符替换字符串中出现的所有 oldChar 字符,并返回替换后的新字符串。

    参数:

         oldChar -- 原字符。

         newChar -- 新字符。

      返回值:替换后生成的新字符串。

    toUpperCase():

     String toUpperCase()

     toUpperCase() 方法将字符串小写字符转换为大写。

      参数:无

     返回值:字符转换为大写后的字符串。

    toLowerCase():

     String toLowerCase()

     toLowerCase() 方法将字符串转换为小写。

     参数:无

    返回值:字符转换为小写后的字符串。

    trim():

     String trim():

     trim() 方法用于删除字符串的头尾空白符。

     参数:无

    返回值:删除头尾空白符的字符串。

  • 相关阅读:
    DAY 206 Python验证常见的50个正则表达式
    DAY 205 python使用ftplib模块实现FTP文件的上传下载
    Jmeter组件介绍
    Jmeter安装
    Jmeter学习笔记
    Jmeter:相应断言介绍
    python time模块
    python+selenium+Eclipse安装
    Python os.path模板函数
    ping 计算机全名,返回的不是IP地址
  • 原文地址:https://www.cnblogs.com/sunshine-z/p/7740048.html
Copyright © 2011-2022 走看看