zoukankan      html  css  js  c++  java
  • StringDemo

    package cn.zuoye;
    /*
     * string类的其他功能
     *
     * 替换功能
     * string replace (char old ,char new)
     * string replace (string old,string new)
     *
     * 去除字符串两个空格(两边)
     * string trim()
     *
     * 按字典顺序比较两个字符串
     * int compareTo(String str)
     * int compareToIgnoreCase(String str)
     */
    public class StringDemo {
     public static void main(String[] args) {
      // 替换功能
      String s1 = "helloworld";
      String s2 = s1.replace('l', 'k');
      System.out.println("s1:"+s1);//s1:helloworld
      System.out.println("s2:"+s2);//s2:hekkoworkd
      
      //去除字符串两空格
      String s3 = "  hello world   ";
      String s4 = s3.trim();
      System.out.println("s3:"+s3+"++++");//s3:  hello world   ++++
      System.out.println("s4:"+s4+"++++");//s4:hello world++++
      
      //按字典顺序比较两个字符串
      String s5 = "hello";
      String s6 = "hello";
      String s7 = "abc";
      String s8 = "xyz";
      System.out.println(s5.compareTo(s6));//0
      System.out.println(s5.compareTo(s7));//7
      System.out.println(s5.compareTo(s8));//-16
        
     }
    }
  • 相关阅读:
    android中文件操作的四种枚举
    【第4节】索引、视图、触发器、储存过程、
    【第3篇】数据库之增删改查操作
    【第2篇】基本操作和存储引擎
    【第1篇】数据库安装
    123
    111
    1111111
    源码
    【COLLECTION模块】
  • 原文地址:https://www.cnblogs.com/rong123/p/9894434.html
Copyright © 2011-2022 走看看