Studyon Minte9.com
Java SE




Format




package testexample; import java.text.MessageFormat; import java.util.Date; public class Test { public static void main(String[] args) { // --- String --- // String s = String.format("Real %s", "Madrid"); System.out.println(s); // Outputs: Real Madrid // --- Number --- // String s2 = String.format("Order number is %d %n", 1000); System.out.println(s2); // Outputs: Order number is 1000 // --- Date --- // String s3 = String.format("Today is %tD %n", new Date()); System.out.println(s3); // Outpus: Today is 02/27/14 Date today = new Date(); String s4 = String.format("Today is %td.%tm.%ty %n", today, today, today); System.out.println(s4);// Outputs: Today is 27.02.14 // --- Left Pad --- // String s5 = String.format("%07d", 7); System.out.println(s5); // Outputs: 0000007 (6 zeros) // --- Message --- // String s6 = MessageFormat.format("Mr. {0} is {1} years old", "John", 45); System.out.println(s6); // Outputs: Mr. John is 45 years old // --- Number of digits --- // int len = String.valueOf(1000).length(); System.out.println(len); // Outputs: 4 // --- Upper First --- // String s7 = org.apache.commons.lang3.StringUtils.capitalize("this is FIRST test."); System.out.println(s7); // Output: This is FIRST test // --- String to lower case --- // String s8 = "AbC".toLowerCase(); System.out.println(s8); // Outputs: abc } }
 


http://docs.oracle.com/javase/tutorial/java/data/numberformat.html
http://docs.oracle.com/javase/tutorial/reflect/member/fieldValues.html