1、StringBuffer类
|
public class APIDemo01 {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer();
buf.append("Hello").append(" ").append("World");
buf.append("\n");
buf.append('A').append(false);
System.out.println(buf);
}
} |
|
public class APIDemo02 {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer();
buf.append("Hello").append(" ").append("World!");
fun(buf) ;
System.out.println(buf);
}
//StringBuffer传递的是引用
public static void fun(StringBuffer b){
b.append("****StringBuffer****");
}
} |
|
Hello World!****StringBuffer**** |
2、包装类
|
NO. |
基本类型 |
包装类 |
|
1 |
short |
Short |
|
2 |
int |
Integer |
|
3 |
long |
Long |
|
4 |
float |
Float |
|
5 |
double |
Double |
|
6 |
char |
Character |
|
7 |
boolean |
Boolean |
|
8 |
byte |
Byte |
|
public class APIDemo03 {
public static void main(String[] args) {
String str = "123" ;
//将字符串变为整型数据
int i = Integer.parseInt(str);
System.out.println("i * 2 = " + (i * 2));
//将字符串变为浮点小数
float f = Float.parseFloat(str) ;
System.out.println("f = " + f);
}
} |
|
i * 2 = 246
f = 123.0 |
3、Runtime类
|
import java.io.IOException;
public class APIDemo04 {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
//调用本机的记事本程序
run.exec("notepad.exe");
} catch (IOException e) {
e.printStackTrace();
}
}
} |
|
import java.io.IOException;
public class APIDemo05 {
public static void main(String[] args) throws Exception{
Runtime run = Runtime.getRuntime();
//调用本机的记事本程序,
Process pro = run.exec("notepad.exe");
//让记事本运行3秒钟
Thread.sleep(3000);
//关闭记事本,即关闭记事本程序
pro.destroy() ;
}
} |
















