s.indexOf()
s.indexOf()
//字符串长度
str.length();
//查找子字符串的位置(索引):
str.indexOf(int c); //c为索引下标
str.indexOf(String str); //String str 为子字符串 从左往右进行查找
str.lastIndexOf(String str); //从右到左进行查找
//获取指定位置的字符:
str.charAt(int index);
//获取子字符串
str.substring(int beginIndex); //索引下标
str.substring(int beginIndex,int endIndex);
str1.indexOf("edu");//查找子字符串的起始位置
str1.indexOf(int I);//查找对应位置的字符
str1.lastindexOf("edu");//从后往前查找子字符串的起始位置
str1.charAt(0);//访问第一个位置的字符;
str1.substring(4,7);//截取指定位置的字符串
字符串信息获取:
String s; //定义字符串
String str1 = "sikieduedu.com" //首位为0号
返回首字母的索引(位置)
------------------------------------------------
s.length(); 字符串的长度
--------------------------------------------
int n = s.index0f("edu"); //n=4;第一个字母的索引
int n = lastIndexOf("edu") //n=7;从后往前开始搜索首字母的索引
当不存在子串返回-1;
--------------------------------------------------
s.charAt(int index); //获取指定位置的字符
---------------------------------------------------
s.substring(int beginIndex); //从开始位置截取子串
s.substring(int beginIndex,int endIndex)
StringDemo
字符串信息获取
查找不到-1 查找到就是第一个字符的索引
String
s.indexOf(String str)
返回一个第一个字符的索引
s.lastIndexOf(String str)
从后向前查找子串,跟上面的方法相反
s.charAt(int index)
输入索引获取对应的字符
import java.until.Scanner;
Scanner s=new Scanner(System.in);
int newwo=s.nextInt()public class
String str1="sikiedu"
查找子串,如果查找不到,返回-1,如果查找到