- public static void main(String[] args) {
- // TODO Auto-generated method stub
- /*
- * 使用for循环遍历数组
- * int arr[]=new int[]{};
- int arr1[][]={{1,2,3,4,5,6,7,8,9},{2,3,6,8,7},{8,5,9,6,7}};
- for (int i = 0; i < arr1.length; i++) {
- for (int j = 0; j < arr1[i].length; j++) {
- int content=arr1[i][j];
- System.out.print(content);
- }
- System.out.println("\n-----------------------------------------------------");
- }*/
- String arr[] = {
- "1",
- "2",
- "3",
- "4",
- "5",
- "3",
- "9"
- };
- //
- //String text="hello.txt;study.java;word.php;hello.word.java;lastnone.c;";
- //System.out.println(text.indexOf("t"));//返回第一次出现t的索引,---6
- //System.out.println(text.lastIndexOf("a"));//返回字符串最后一次出现的a的索引位置--47
- //System.out.println(text.lastIndexOf(".java"));//返回字符串最后一次出现的.java的索引位置--47
- //char ch= text.charAt(4);//返回一个char类型的字符串
- //String re=ch+"";
- //System.out.println(re.toUpperCase());//toUpperCase();把小写字母转成大写字母,返回类型为String类型
- //System.out.println(text.charAt(4));//返回字符串索引值为4的那一个字符为o
- //System.out.println("字符串的长度为:"+text.length());
- //-----------------------------------------------------------------------------------------------------------------------
- //找出字符串中以.java结尾的字符串,分隔符为;
- String text = "hello.txt;study.java;word.php;hello.word.java;lastnone.c;";
- String rest[] = text.split(";"); //用split方法去分割字符串,返回的是一个string数组,必须用一个String数组去接收
- for (String i: rest) {
- int re = i.lastIndexOf(".java");
- if (re > 0) { //判断每一个字符串是否有.java结尾的,有就输出,没有就跳过进入下一次循环
- System.out.println(i);
- } else {
- continue;
- }
- } //用foreach循环语句去遍历数组,for(元素变量 x:遍历的对象 obj){引用x的java语句}
- //-----------------------------------------------------------------------------------------------------------------------
- }
来源: http://www.bubuko.com/infodetail-2005579.html