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

    }

  • 相关阅读:
    XmLHttpRequst下载Excel
    mysq for visual studio 1.1.1
    滚动条样式设置
    正则
    比较偏门的JVM语言Quercus
    OMG 在线思维导图都有开源的
    从几篇文字得到关于web app开发的性能问题的答案
    用linux遇到的一个死循环
    有道笔记
    FreeBSD 10 发布
  • 原文地址:https://www.cnblogs.com/51testing/p/7872789.html
Copyright © 2011-2022 走看看