Java String Truncate truncate(String s)

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

Description

truncate

License

Open Source License

Declaration

public static String truncate(String s) 

Method Source Code

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

public class Main {
    /**//from  ww  w  .j  ava  2  s .  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 message, String substring)
  2. truncate(String original, int number)
  3. truncate(String original, String ellipsis, int maxLength)
  4. truncate(String originalString, int size)
  5. truncate(String s)
  6. truncate(String s, int begin, int end)
  7. truncate(String s, int i)
  8. truncate(String s, int length)
  9. truncate(String s, int length)