[JAVA] String Formatter 的使用

有時寫程式時, 會將variable放入string中, 若要放入的variable數量少及簡單的話, 通會寫法如下:

String fruit="apple";
String result="I love "+fruit;

然而, 有時為了令程式更有readability (可讀性), 會寫成:

String name="Ling"
String fruit="apple";</code>

String result=String.format("%s love %s",name,fruit);

好處是可以令string 的格式直觀顯示出來, 但若有variable增刪時, 則有機會令其混亂.

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.