Java String Truncate truncate(String s, int length)

Here you can find the source of truncate(String s, int length)

Description

Truncate the input string to be at most the input length

License

Open Source License

Parameter

Parameter Description
s The string to truncate
length The maximum length

Return

A truncated string with length 15, or the input string

Declaration

public static String truncate(String s, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//ww  w .ja  va 2s.  c o  m
     * Truncate the input string to be at most the input length
     * @param s The string to truncate
     * @param length The maximum length
     * @return A truncated string with length 15, or the input string
     */
    public static String truncate(String s, int length) {
        if (s.length() <= length)
            return s;
        return s.substring(0, length);
    }

    public static String truncate(String s) {
        return truncate(s, 15);
    }
}

Related

  1. truncate(String originalString, int size)
  2. truncate(String s)
  3. truncate(String s)
  4. truncate(String s, int begin, int end)
  5. truncate(String s, int i)
  6. truncate(String s, int length)
  7. truncate(String s, int length, boolean indicator)
  8. truncate(String s, int max_len)
  9. truncate(String s, int maxLength)