Java Char Create toCharListNumber(int value, String list)

Here you can find the source of toCharListNumber(int value, String list)

Description

Create a string which represents the specified value using the specified list of characters.

License

Open Source License

Parameter

Parameter Description
value the value. Must be >= 1.
list the character list to use. Must contain at least 4 characters.

Exception

Parameter Description
IllegalArgumentException if the value is < 1

Return

the formated number

Declaration

public static String toCharListNumber(int value, String list)
        throws IllegalArgumentException 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww.  ja v a 2 s .  c om
     * Create a string which represents the specified value using the specified list of characters.
     * @param value the value. Must be >= 1.
     * @param list the character list to use. Must contain at least 4 characters.
     * @return the formated number
     * @throws IllegalArgumentException if the value is < 1
     */
    public static String toCharListNumber(int value, String list)
            throws IllegalArgumentException {
        if (value < 1) {
            throw new IllegalArgumentException("value");
        }
        int pos = 16;
        char[] tmp = new char[pos];
        do {
            tmp[--pos] = list.charAt(--value % list.length());
            value /= list.length();
        } while (value > 0);
        return new String(tmp, pos, tmp.length - pos);
    }
}

Related

  1. toCharacter(Object object)
  2. toCharacter(Object value)
  3. toCharacter(String input, char defaultValue)
  4. toCharacter(String str, String charset)
  5. toCharCode(String s)
  6. toChars(byte b, char[] result, int position)
  7. toChars(final int cp, final char[] buffer, final int offset)
  8. toChars(int codePoint, char[] dst, int dstIndex)
  9. toChars(int number, char chars[])