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);

  • 相关阅读:
    Redis 5.0 redis-cli --cluster
    Redis使用redis-trib.rb创建带密码的集群问题总结
    Docker实战之Redis-Cluster集群
    kafka作为流式处理的上一层,为什么吞吐量那么大?
    LAMP 实现全过程及wordpress的搭建
    mysql
    Mysql读写分离方案-MySQL Proxy环境部署记录
    Centos7.5部署MySQL5.7基于GTID主从复制+并行复制+半同步复制+读写分离(ProxySQL)
    iptables
    Nginx+Keepalived高可用集群
  • 原文地址:https://www.cnblogs.com/wang01/p/9812530.html
Copyright © 2011-2022 走看看