package com.heima;
import java.util.Arrays;
public class Demo_Lianxi {
/**
* 心得
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr0 = {12,89,56,34,76,98,100};
String s = "abcde23456789";
System.out.print("将字符串转化成数组是:");
char[] arr = s.toCharArray();
System.out.print("[");
for (int i = 0; i < arr.length; i++) {
if (i != arr.length - 1) {
System.out.print(arr + ",");
}else {
System.out.println(arr + "]");
}
}
System.out.println("转化为大写是:" + s.toUpperCase());
System.out.println("反转后的字符串是:" + new StringBuffer(s).reverse());
System.out.println("截取前四个字符串是:" + s.substring(0,5));
System.out.println("s数组的长度是:" + s.toCharArray().length);
System.out.println("s的字符串的长度是" + s.length());
System.out.println("索引为4的字符是:" + s.charAt(4));
System.out.println("索引为12的字符是:" + s.charAt(12));
System.out.println("索引为4的字符是:" + s.charAt(0));
System.out.println("的索引是:" + s.indexOf('8'));
System.out.println("的索引是:" + s.indexOf('9'));
System.out.println(Arrays.binarySearch(arr, '5'));
System.out.println(Arrays.binarySearch(arr, 'a'));
System.out.println(Arrays.binarySearch(arr, '9'));
Arrays.sort(arr0);
System.out.println(Arrays.binarySearch(arr0, 98));
System.out.println("最后声明所有程序员:" + String.valueOf(arr).replace(s,"不忘初衷,方得始终,继续加油,洞房白富美"));
}
}
|
|