/**
*
*/
package cm.string;
/**
* @author 这个类用来测试String的使用
*
*/
public class Test1_String2 {
/**
*
*/
public Test1_String2() {
// TODO Auto-generated constructor stub
}
/**日常小黄线:The value of the local variable string is not unused;
* 日常小注解:Add @SuppressWarnings 'unused' to main();*/
public static void main(String[] args) {
String s = "woaini";
char c = s.charAt(0);
System.out.println(c);
int i = c;
System.out.println(i);
char[] t = {'冲', '夏', '天'};
String string = new String(t);
System.out.println(string);
char h = string.charAt(1);
System.out.println(h);
char[] str = new char[] {'勇', '敢', '前', '进'};
String ing = new String(str);
string = string.concat(ing);
System.out.println(string);
String boy = new String(str);
System.out.println(boy);
char[] rr = new char[] {'白', '色', '风', '车'};
String ss = new String(rr);
ss = boy.concat(ss);
boy = ss.concat(boy);
System.out.println(ss);
System.out.println(boy);
System.out.println(boy.contains(ss));
System.out.println(boy.equals(ss));
System.out.println(boy.endsWith("进"));
System.out.println(string);
System.out.println(string.equals("冲夏天勇敢前进"));
byte[] b = boy.getBytes();
System.out.println(b);
System.out.println(b[0]);
char[] q = {'f', 'd', 'a', 's'};
String n = new String(q);
System.out.println(n);
byte[] w = n.getBytes();
System.out.println(w);
System.out.println(w[0]);
for(int e = 0; e<w.length; ++e) { //Arrays.toString(数组);
System.out.print(w[e] + "、");
}
System.out.println(); //换行
//String类中的hashCode()源码:返回此字符串的哈希码。
System.out.println(n.hashCode());
System.out.println(n.getBytes()); //数组对象地址值:[B@2ed94a8b
System.out.println(w); //byte数组w的地址值[B@73f792cf
System.out.println(n.isEmpty());
System.out.println(n.indexOf("as"));
System.out.println(n.indexOf("s"));
System.out.println(n.lastIndexOf("sis"));
System.out.println(n.length());
}
}
API常用类库之一String的基本作用介绍
最新推荐文章于 2021-12-24 00:15:54 发布