原創|其它|編輯:郝浩|2009-10-16 10:54:57.000|閱讀 466 次
概述:本文介紹了在Java中如何避免tostring方法的誤操作。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
public class GotchaString {
public static void main(String arg[]) {
System.out.println("string + twenty + thirty: " + 20 + 30);
System.out.println("string + (twenty + thirty): " + (20 + 30));
System.out.println(20 + 30 + " twenty + thirty + string");
System.out.println(20 + "" + 30 + " twenty + string + thirty + string");
}
}
第一個是2030
第二個是50
第三個是50
第四個是2030
所以要是第一個是數字的話,中間可以加上一個空string進行明示。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:IT專家網