SDN Featured Content

Do you Think Hibernate is better technology that EJB

Java/J2EE blogs

Welcome to my java /J2EE blogs.


Thursday, June 3, 2010

Good example of System.out.format method

You can use this new feature to quickly format strings into table :

public class Table{
public static void main(String args[]){
String format = "|%1$-10s|%2$-10s|%3$-20s|\n";
System.out.format(format, "FirstName", "Init.", "LastName");
System.out.format(format, "Ajay", "", "Kumar");
System.out.format(format, "Sunil", "Dr", "Bainsla");

System.out.format(String.format(format, (Object[])ex));
}
}


Output:



|FirstName |Init.     |LastName           |
|Ajay | |Kumar |
|Sunil |Dr |Bainsla |

No comments: