1 CharAt(index) : 通过他的索引来获取元素

@Test
	public void test1(){
		String a="dfjkdjfd134";
		for(int i=0;i<a.length();i++){
			System.out.print(a.charAt(i)+"  ");
		}
		
	}
 答案:d  f  j  k  d  j  f  d  1  3  4  

2  indexOf(String s) : 返回当前字符串的索引,字符串索引的位置从0开始

  indexOf(String s,int startpoint) 方法是从当前字符串的startpoint位置开始索引字符串s

String tom="I am a good cat"indexOF(String;
tom.indexOf("a");   // 值是2
tom.indexOf("good",2);   //值是7
tom.indexOf("a",7);  //值是13
tom.index.of("w",2);   //值是-1

 

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-11-13
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
猜你喜欢
  • 2022-12-23
  • 2021-10-16
  • 2021-07-30
  • 2022-12-23
  • 2021-07-08
  • 2022-03-02
  • 2022-12-23
相关资源
相似解决方案