Java Integer Clamp clamp(String string, int maxChars)

Here you can find the source of clamp(String string, int maxChars)

Description

clamp

License

Open Source License

Declaration

public static String clamp(String string, int maxChars) 

Method Source Code

//package com.java2s;

public class Main {
    public static String clamp(String string, int maxChars) {

        if (containsData(string) && string.length() > maxChars) {
            string = string.substring(0, maxChars) + "...";
        }//ww  w  . j ava  2  s . c  o m
        return string;
    }

    /**
     * Test is the given String is not NULL and if it contains more then one character.
     *
     * @param string
     * @return
     */
    public static boolean containsData(String string) {
        if (string == null) {
            return false;
        }
        return string.length() > 0;
    }
}

Related

  1. clamp(int value, int min, int max)
  2. clamp(int value, int minValue, int maxValue)
  3. clamp(int var, int min, int max)
  4. clamp(int x, int min, int max)
  5. clamp(int x, int min, int max)
  6. clamp_int(int num, int min, int max)
  7. clamp_wrap(int a, int x, int y)
  8. clampAngle(int angle)
  9. clampByte(int in)