Java String Truncate truncate(String s, int i)

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

Description

Truncates a String s to length i or less

License

Open Source License

Declaration

public static String truncate(String s, int i) 

Method Source Code

//package com.java2s;

public class Main {
    /** Truncates a String s to length i or less */
    public static String truncate(String s, int i) {
        if (s == null) {
            return null;
        }//from ww w  . j a v  a 2 s .  c om
        if (i < 1) {
            return null;
        }
        if (s.length() > i) {
            return s.substring(0, i);
        } else {
            return s;
        }
    }
}

Related

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