package cn.itcast_06;

/*

  • 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) {
// TODO Auto-generated method stub
//替换功能
String s1 = "helloworld";
String s2 = s1.replace('l', 'k');
String s3 = s1.replace("ll", "kk");
String s4 = s1.replace("ll", "kkkkk"); System.out.println("s1:" + s1);//helloworld
System.out.println("s2:" + s2);//hekkoworkd
System.out.println("s3:" + s3);//hekkoworld
System.out.println("s4:" + s4);//hekkkkkoworld //去除字符串两端空格:String trim()
String s5 = " hello world ";
String s6 = s5.trim();
System.out.println("s5:" + s5 + "---");
System.out.println("s6:" + s6 + "---"); //按字典顺序比较两个字符串(大小)
String s7 = "hello";
String s8 = "hfllo";
String s9 = "gbc";
String s10 = "xyz";
System.out.println(s7.compareTo(s7));//0
System.out.println(s7.compareTo(s8));//-1
System.out.println(s7.compareTo(s9));//1
System.out.println(s7.compareTo(s10));//-16 }

}

String的用法——其他功能的更多相关文章

  1. String的用法——转换功能

    package cn.itcast_05; /* String类的转换功能: byte[] getByte():把字符串转换成字节数组 复习: public String(byte[] bytes): ...

  2. String的用法——获取功能

    package cn.itcast_04; /* String类获取功能 int length():获取字符的长度 char charAt(int index):获取指定索引位置的字符 int ind ...

  3. String的用法——判断功能

    package cn.itcast_03; /* String的判断功能: 1.boolean equals(Object obj):字符串的内容是否相同,区分大小写 2.boolean equals ...

  4. string类的常用功能演示

    这个程序可用随着我对string的用法的增多而有调整. /* 功能说明: string类的常用功能演示. 实现方式: 主要是演示string的常用函数的用法和它与字符数组的区别与联系 限制条件或者存在 ...

  5. test命令用法。功能:检查文件和比较值

    test命令用法.功能:检查文件和比较值 1)判断表达式 if test  (表达式为真) if test !表达式为假 test 表达式1 –a 表达式2                  两个表达 ...

  6. C#中string.format用法详解

    C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...

  7. String.format()用法

    package junit.test;   import java.util.Date; import java.util.Locale;   import org.junit.Test;   pub ...

  8. java11-6 String类的其它功能

    String类的其他功能: 替换功能: String replace(char old,char new) String replace(String old,String new) 去除字符串两空格 ...

  9. java11-3 String类的获取功能

    String类的获取功能 int length():获取字符串的长度. char charAt(int index):获取指定索引位置的字符 int indexOf(int ch):返回指定字符在此字 ...

随机推荐

  1. SpringBoot项目报错Cannot determine embedded database driver class for database type NONE

    原因: Cannot determine embedded database driver class for database type NONE 这是因为spring boot默认会加载org.s ...

  2. NoSQL之Redis探析

    下载地址:wget http://download.redis.io/releases/redis-2.8.8.tar.gz安装steps:1 下载Official Website : http:// ...

  3. 2012年公司组织旅游西安线个人记录(repost)

    2012年公司组织旅游西安线个人记录 文件夹 [隐藏]  1 序言 2 第1天 3 第2天 4 第3天 5 第4天 6 第5天 [title=2012%E5%B9%B4%E5%85%AC%E5%8F% ...

  4. Installation error: INSTALL_FAILED_CPU_ABI_INCOMPATIBLE

    解决方法: http://my.oschina.net/u/242764/blog/375909 当我们安装好Genymotion后,把Android运用部署到上面调试时,console 控制台会报错 ...

  5. GrideView(三)---编辑功能实现

    GrideView(三)---编辑 法一.(优势:操作数据更加灵活:劣势: 书写较多代码,开发效率低) 通过编辑列---添加超链接(HyperlinkField)字段 ,来跳转页面实现编辑操作: 步骤 ...

  6. bzoj2823: [AHOI2012]信号塔&&1336: [Balkan2002]Alien最小圆覆盖&&1337: 最小圆覆盖

    首先我写了个凸包就溜了 这是最小圆覆盖问题,今晚学了一下 先随机化点,一个个加入 假设当前圆心为o,半径为r,加入的点为i 若i不在圆里面,令圆心为i,半径为0 再重新从1~i-1不停找j不在圆里面, ...

  7. MyEclipse8.5优化

    MyEclipse8.5优化 第一步: 取消自动validation validation有一堆,什么xml.jsp.jsf.js等等,我们没有必要全部都去自动校验一下,只是需要的时候才会手工校验一下 ...

  8. sphinx测试数据生成

    import json from random import sample, randint from uuid import uuid4 def gen_random_words(): with o ...

  9. 转【前端基础进阶之Promise】

    前言 Promise的重要性我认为我没有必要多讲,概括起来说就是必须得掌握,而且还要掌握透彻.这篇文章的开头,主要跟大家分析一下,为什么会有Promise出现. 在实际的使用当中,有非常多的应用场景我 ...

  10. 2-3 Windows下一站式开发环境anaconda搭建

    D:\Users\ZHONGZHENHUA\Anaconda3\Scripts\activate.bat https://www.geforce.com/hardware/notebook-gpus/ ...