java常用類,java
一:StringBuffer類
1. 字串反轉
public class Demo1 {
public static void main(String[] args) {
StringBuffer buf=new StringBuffer();
buf.append(“hello”);
//把buf內容倒過來輸出
//原理資料結構中的出棧和入棧原理
String str=buf.reverse().toString();
System.out.println(str);
}
}
public class Demo1 {
public static void main(String[] args) {
StringBuffer sbf=new StringBuffer();
sbf.append(“Spring”);
for(int i=0;i<10;i++){
sbf.append(i);
}
System.out.println(sbf);
}
}
二:Runtime類
概念:表示運行時操作的類,是一個封裝了JVM進程的類,在JVM運行時執行個體化。
Runtime run=Runtime.getRuntime();
三:System類
概念:其中的所以屬性和方法都是靜態,直接調用即可
1. 測試程式已耗用時間
long start=System.currentTimeMillis();
int sum=0;
for(int i=0;i<10000000;i++){
sum+=i;
}
System.out.println(sum);
long end=System.currentTimeMillis();
System.out.println(end-start);
四:日期操作類
1. 日期格式
DateFormat df1=null;
DateFormat df2=null;
df1=DateFormat.getDateInstance();
df2=DateFormat.getDateTimeInstance();
System.out.println(df1.format(new Date()));
System.out.println(df2.format(new Date()));
著作權聲明:博主原創文章,轉載請說明出處。http://blog.csdn.net/dzy21