Java examples for java.lang:String Truncate
The following code shows how to truncate String
//package com.java2s; public class Main { public static void main(String[] argv) { String name = "java2s.com"; System.out.println(truncateString(name)); }//from w w w .j a v a2 s . c om private static final int TRUNCATE_LENGTH = 60; public static String truncateString(String name) { if (name != null && name.length() > TRUNCATE_LENGTH) { return name.substring(0, TRUNCATE_LENGTH) + " ..."; } return name; } }