zoukankan      html  css  js  c++  java
  • String类中一些常用的函数

    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
  • 相关阅读:
    Java 类和对象12
    Java类和对象11
    java 类和对象10
    Java类和对象9
    Java类和对象8
    Java 类和对象7
    包装与方法
    JAVA链表
    泛型
    多态 接口
  • 原文地址:https://www.cnblogs.com/yaobolove/p/5940057.html
Copyright © 2011-2022 走看看