zoukankan      html  css  js  c++  java
  • 《字符串的概念》

    一.创建String 类型对象的3种方式

      1.String name=new String();
      2.String name=new String("张三");
      3.String name="李四";

    二.==和equals()方法的区别

        ==:用来比较数值类型,如果用==比较String(引用类型),会比较内存首地址是否相等

        equalus()方法:用来比较两个字符串的值是否相等

    三.正则表达式

    四.字符串常用方法

      1.查找指定字符串位置

        public int indexOf(int ch) 搜索第一个出现的字符ch(或字符串value)
        public int indexOf(String value)
        public int lastIndexOf(int ch) 搜索最后一个出现的字符ch(或字符串value)
        public int lastIndexOf(String value)

    2.截取字符串
        public String substring(int index) 提取从位置索引开始的字符串部分
        public String substring(int beginindex,int endindex) 提取beginindex和endindex之间的字符串部分
        public String trim() 返回一个前后不含任何空格的调用字符串的副本
    3.拼接字符串
      1.使用"+"号
      2.使用concat()方法
      4.比较两个字符串的值
      equals()
      equalsIgnoreCase()忽略大小写
    5.字符串转换大小写
    toUpperCase()转换为大写
    toLowerCase()转换为小写
    6.字符串长度:length()
    7.字符串分割split()
    String str="长亭外,古道边,芳草碧连天,晚风拂 柳笛声残 夕阳山外山";
    //根据什么分割
    String[] split = str.split(",");
    for (int i = 0; i < split.length; i++) {
    System.out.println(split[i]);
    }
    五.StringBuffer
    StringBuffer:String增强版
    创建StringBuffer对象:
    StringBuffer sb = new StringBuffer();
    StringBuffer sb = new StringBuffer("aaa");

    六.StringBuffer对象的常用方法(append(),insert(),toString())

    StringBuffer sb=new StringBuffer("超级演说家马上开始");
    //拼接字符串
    sb.append("!");
    //再指定位置插入字符串
    sb.insert(5, ",");
    //从StringBuffer对象转换为String对象
    String string = sb.toString();
    System.out.println(string);

  • 相关阅读:
    js 的关键字
    如何理解闭包?
    post请求下载文件,获取Content-Disposition文件名
    reactjs踩坑记
    原生js的一些盲点
    js深拷贝
    使用 event.preventDefault() 时报错 Unable to preventDefault inside passive event listener invocation.
    vue项目中 在index.html里引入css不生效的解决方式
    Do not access Object.prototype method‘hasOwnProperty’ from target object no-prototype-builtins
    AJAX详解
  • 原文地址:https://www.cnblogs.com/lowerma/p/9810788.html
Copyright © 2011-2022 走看看