API手册
下载jdk1.5手册
注意:chm文件从网络下载后,菜单能展现点击后内容不能展现,按下面图修改下即可 
api
了解即可,用到具体的api会用 System.in,System.out.println 日常常用的不到20% 
字符串工具类

package test;
import java.util.Arrays;
import org.junit.Test;
public class TestString {
@Test
public void concat() {
System.out.println("hello" + " world." + " hi");
System.out.println("hello".concat(" world.").concat(" hi"));
String str = "hello world.";
System.out.println("字符串长度:" + str.length());
}
@Test
public void trim() {
String s = " 达内 CGB java大数据方向 ";
System.out.println( s.trim() );
}
@Test
public void charAt() {
String s = "达内CGB方向";
System.out.println(s.charAt(0));
System.out.println(s.charAt(2));
System.out.println(s.charAt(s.length()-1));
}
@Test
public void substring() {
String s = "达内CGB Java大数据方向很棒";
System.out.println( s.substring(0,2) );
System.out.println( s.substring(6, 13));
System.out.println( s.substring(13) );
}
@Test
public void toCase() {
String name = "Chen ZiShu";
System.out.println(name.toUpperCase());
System.out.println(name.toLowerCase());
String className = "PersonMan";
String s1 = className.charAt(0)+"";
s1 = s1.toLowerCase();
System.out.println(s1);
String s2 = className.substring(1);
System.out.println(s2);
System.out.println(s1.concat(s2));
}
@Test
public void indexOf() {
String s = "周杰伦.双.节.棍.mp3";
int pos1 = s.indexOf(".");
System.out.println("位置:"+pos1);
System.out.println( s.substring(0, pos1) );
int pos2 = s.lastIndexOf(".");
System.out.println( s.substring(0, pos2) );
System.out.println( s.substring(pos2+1) );
}
@Test
public void with() {
String name = "http://www.baidu.com";
if( name.startsWith("http://")) {
System.out.println("这是一个HTTP网站");
}else {
System.out.println("这是其他类型的网站");
}
if( name.endsWith(".cn")) {
System.out.println("cn中国公司");
}else if( name.endsWith(".com") ) {
System.out.println("com全球公司");
}else if( name.endsWith(".net") ) {
System.out.println("net网络提供商");
}
}
@Test
public void regex() {
String s = "王180a,李133b,陈139c,张130d";
String r = "";
for(int i=0; i<s.length(); i++) {
char c = s.charAt(i);
if(c>=48 && c<=57) {
c = '*';
}
r += c;
}
System.out.println(r);
System.out.println(
s.replaceAll("\\d", "*").replaceAll("[a-z]", "+")
);
}
@Test
public void replace() {
String s = "刘若英.后天.mp3";
System.out.println( s.replace(".", "*") );
System.out.println( s.replaceAll("\\.", "*") );
}
@Test
public void split() {
String s = "刘若英.后天.mp3";
String[] arr = s.split("\\.");
System.out.println( Arrays.toString(arr));
String type = "手机,电视,冰箱,烧水壶,空调";
System.out.println( Arrays.toString(type.split(",")));
String grade = "100;90;88;120;80";
System.out.println( Arrays.toString(grade.split(";")));
}
@Test
public void star() {
String s = "刘德华,张曼玉,齐秦,周星驰";
String[] names = s.split(",");
for(int i=0; i<names.length; i++) {
String name = names[i];
System.out.println( name );
String r = name.substring(0,1);
for(int j=1; j<name.length(); j++) {
r += "*";
}
System.out.println(r);
}
}
}
身号解析
package test;
import org.junit.Test;
public class TestCardNo {
@Test
public void cardNo() {
String cardNo = "610113198009102113";
if(cardNo.length()==18) {
String address = cardNo.substring(0,6);
System.out.println("地址码:"+address);
String birthday = cardNo.substring(6,14);
System.out.println("出生年月:" + birthday);
String sno = cardNo.substring(14,17);
System.out.println("顺序号:" + sno);
String x = sno.substring(2);
System.out.println(x);
int i = Integer.parseInt(x);
if(i%2==0) {
System.out.println("性别:女");
}else {
System.out.println("性别:男");
}
System.out.println("校验码:" + cardNo.substring(17));
}else {
System.out.println("身号不正确");
}
}
}
小结
1)API,java提供应用程序接口(插线板)就可以按规则来写程序, 写程序有了java(JDK)就像搭积木,事半功倍,开发效率就高。 这才是java核心,主要就是学习这些api的用法。(多练习,api的组合去完成需求) API需要一定背 
|