String类中常用的一些个方法

代码测试: 

package com.lzw.demo;

/**
 * @author lzw
 * @Date 2019年4月11日
 */
public class Dmoe {
    private static String str = "abcde12d3456";
    private static String str2 = "  123456abc   ";
    public static void main(String[] args) {
        System.out.println("equals()---:"+str.equals(str2));//输出true或者false 比较两个字符串
        System.out.println("length()---:"+str.length());//输出字符串的长度
        System.out.println("indexOf()---:"+str.indexOf("d"));//输出指定字符第一次在字符串中的位置
        System.out.println("charAt()---:"+str.charAt(3));//输出指定位置的值;起始为0
        System.out.println("replace()---:"+str.replace("12", "ggg"));//字符串替换
        System.out.println("trim()---:"+str2.trim());//去除字符串首尾的空格
        System.out.println("substring()---:"+str.substring(4)+":"+str.substring(2, 6));//截取字符串
    }

}

输出结果:

equals()---:false
length()---:12
indexOf()---:3
charAt()---:d
replace()---:abcdegggd3456
trim()---:123456abc
substring()---:e12d3456:cde1

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值