java常用類,java

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.