Java String Truncate truncate(String str, int max)

Here you can find the source of truncate(String str, int max)

Description

Ensure that the given string is no more than 'max' characters long.

License

Academic Free License

Declaration

public static String truncate(String str, int max) 

Method Source Code

//package com.java2s;
// Licensed under the Academic Free License version 3.0

public class Main {
    /**/*w  ww .j a  va 2s .  c  om*/
     * Ensure that the given string is no more than 'max' characters long.
     */
    public static String truncate(String str, int max) {
        return (str.length() > max) ? str.substring(0, max) : str;
    }
}

Related

  1. truncate(String str, int length)
  2. truncate(String str, int length)
  3. truncate(String str, int length)
  4. truncate(String str, int length)
  5. truncate(String str, int max)
  6. truncate(String str, int maxLen)
  7. truncate(String str, int maxSize)
  8. truncate(String str, int maxSize)
  9. truncate(String str, int n)