String Padding in Java

digg_url = “http://coozplz.blogspot.com/2012/02/string-padding-in-java.html”;digg_title = “String Padding in Java”;digg_bgcolor = “#FFFFFF”;digg_skin = “normal”;digg_url = undefined;digg_title = undefined;digg_bgcolor = undefined;digg_skin = undefined;

[출처]http://stackoverflow.com/questions/388461/how-can-i-pad-a-string-in-java

 

String phoneNumber = "4000";

String leftPadd = String.format("%-10s", 

phoneNumber);

String rightPadd = String.format("%10s", 

phoneNumber);

System.out.println(leftPadd);

System.out.println(rightPadAd);

Result:

4000     
      4000

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s