zoukankan      html  css  js  c++  java
  • java中的字符串一

    public class TestString2 {

    public static void main(String[] args) {
    //判断两字符串是否相等
    String s1 = "Hello world";
    String s2 = "Hello java";
    if (s1.equals(s2)) {
    System.out.println("equal");
    }else{

    System.out.println("not equal");
    }
    System.out.println("------------");
    //判断s1是否以He开头
    if (s1.startsWith("He")) {
    System.out.println("begin with He");
    }
    //判断s1是否以He结尾
    if (s1.endsWith("world")) {
    System.out.println("end with world");
    }
    //返回s1中字母d的下标
    System.out.println("返回s1中字母d的下标为:"+s1.indexOf('d'));
    //返回索引从3到8的子字符串
    System.out.println("返回索引从3到8的子字符串" + s1.substring(3,8));
    //拼接
    System.out.println("拼接到后面"+s1.concat("abcd"));
    //替换单个字母
    System.out.println("替换单个字母"+s1.replace('H','z'));
    //替换第一个字母
    System.out.println("替换第一个字母"+s1.replaceFirst("H","AABB"));
    //是否包含world
    System.out.println("是否包含world "+ s1.contains("world"));
    //根据空格切割
    System.out.println("根据空格切割 "+s1.split(" ")[0] +" " + s1.split(" ")[1] );
    }

    }

  • 相关阅读:
    剑指offer二十九---最小的k个数
    Select2插件 点击、选中事件 解读
    Datatable插件的简单的使用方式 和 学习方式
    java map获取值方式
    mysql delete语句使用别名报错
    springmvc 添加@ResponseBody
    maven 创建后报错
    nodejs
    gulp
    Nodejs-express 4.0框架 简单介绍
  • 原文地址:https://www.cnblogs.com/51testing/p/7872789.html
Copyright © 2011-2022 走看看