Here you can find the source of truncate(String str, int maxSize)
Parameter | Description |
---|---|
str | the string to possibly truncate |
maxSize | the maximum size of the string |
str
param is null, then the returned string will also be null.
public static String truncate(String str, int maxSize)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 public class Main { /**// w w w . j ava2s. com * Truncate a string to a max size. * * @param str the string to possibly truncate * @param maxSize the maximum size of the string * @return the truncated string. if <code>str</code> param is null, then the returned string will also be null. */ public static String truncate(String str, int maxSize) { if (str == null) { return null; } if (str.length() <= maxSize) { return str; } return str.substring(0, maxSize); } }