Display at most 15 characters in a string in Java
Description
The following code shows how to display at most 15 characters in a string.
Example
// w ww .j av a 2 s .co m
import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt = new Formatter();
fmt.format("%.15s", "Formatting with Java is now easy.");
System.out.println(fmt);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »