zoukankan      html  css  js  c++  java
  • 字符串

    一创建String类型对象的三种方式:

      

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

    二:==与  .equals()的区别:

      ==:用于比较数据类型,如果用于比较String类型,则比较的是内存首地址;

      .equals():用来比较两个字符串是否相等;

    三:字符串常用方法:

      1.查找字符串的位置:

        搜索在字符串中第一个出现的ch或字符串value

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

       2.截取字符串:

        提取从位置开始的字符串部分

    public String substring(int index);

        提取从de到de之间的字符串部分

    public String substring(int be,int be);

        返回一个前后不含任何空格的调用字符串副本

    public String trim();

       3.拼接字符串:

        1:使用“+”号

        2:concat()方法

      4.比较:

        1: .equals();

        2: .equalslgnoreCase()     //忽略大小写

      5.字符串大小写转换

        1:toUpperCase()    //转为大写

        2:toLowerCase()   //转为小写

      6.字符串长度

        1:    .length();

      7.字符串分割制

        

    String str="123,123,123,123";
    //根据什么分割
    String [] split=str.split(",");
    for(int i=0;i<split.length;i++){
        System.out.println(split[i]);
    }

    四:StringBuffer:

        1.StringBuffer:是String的增强版

        2.创建StringBuffer的对象

          StringBuffer sb =new StringBuffer();

          StringBuffer sb =new StringBuffer("啊啊啊");

    五:StringBuffer的使用方法

      (append ();   insert();    toString())

      

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

    有任何问题可随时联系我QQ:2838509529     原创:梅川酷子

  • 相关阅读:
    摄影测量技术和立体捕捉
    面向 Unity* 软件和虚拟现实的优化:运行时生成内容
    优化 VR 动作类游戏《Space Pirate Trainer*》以便在英特尔® 集成显卡上实现卓越的表现
    VR电竞游戏在英特尔®架构上的用户体验优化
    《物质世界 (Outward)》证明不必压缩制作大型角色扮演游戏的时间
    采用棋盘渲染在英特尔集成显卡上进行实时升级
    数字绘画:快节奏绘画流程
    实时模型 — 超越多边形计算
    舆情文本分析
    python评分卡
  • 原文地址:https://www.cnblogs.com/whtt/p/9812643.html
Copyright © 2011-2022 走看看