java 字符串获取功能:下

package cn.tx.demo;

import java.util.Arrays;

//字符串获取功能:下.
public class StringTest1 {
public static void main(String[] args) {
String s = “helloworld”;
//从某一个索引开始向后数第一次出现的子字符串的索引
int i = s.indexOf(“ow”,1);
System.out.println(i);
//截取指定的索引之后的字符串并且包含索引处的字符
String substring = s.substring(5);
System.out.println(substring);
//截取指定的开始索引和结束索引的字符串且不包含结
// 束索引处的字符,即包头不包尾.
String substring1 = s.substring(5,7);
System.out.println(substring1);
//获得这个字符串对应的字符的数组;Arrays数组,toString将数值转换成字符串
byte[] bytes = s.getBytes();
System.out.println(Arrays.toString(bytes));
//把字符串转换成字符的数组
char[] chars = s.toCharArray();
System.out.println(Arrays.toString(chars));

}

}
在这里插入图片描述

发布了103 篇原创文章 · 获赞 5 · 访问量 3058

猜你喜欢

转载自blog.csdn.net/weixin_45339692/article/details/103774341
今日推荐