Java Number Max Value max(String content, int max, String dotDotDot)

Here you can find the source of max(String content, int max, String dotDotDot)

Description

max

License

LGPL

Declaration

public static String max(String content, int max, String dotDotDot) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from ww  w  .j  ava 2 s .  c  om*/
     * cut string to max size if the string is greater, otherweise to nothing
     * @param content
     * @param max 
     * @return cutted string
     */

    public static String max(String content, int max) {
        return max(content, max, "");
    }

    public static String max(String content, int max, String dotDotDot) {
        if (content == null)
            return null;
        if (content.length() <= max)
            return content;

        return content.substring(0, max) + dotDotDot;
    }

    public static int length(String str) {
        if (str == null)
            return 0;
        return str.length();
    }

    /**
     * this method works different from the regular substring method, the regular substring method takes startIndex and endIndex as second and third argument,
     * this method takes offset and length
     * @param str
     * @param off
     * @param len
     * @return
     */
    public static String substring(String str, int off, int len) {
        return str.substring(off, off + len);
    }
}

Related

  1. max(Number n0, Number n1)
  2. max(Number num1, Number num2)
  3. Max(Object in)
  4. max(Object o1, Object o2)
  5. max(String a, String b)
  6. max(String left, String right)
  7. max(String name)
  8. max(String s)
  9. max(T a, T b)