Java Integer to intToLetter(int index)

Here you can find the source of intToLetter(int index)

Description

Returns the 0-indexed String index correlating to the given integer index

License

Apache License

Parameter

Parameter Description
index integer index to convert

Return

the 0-indexed String index correlating to the given integer index

Declaration

public static String intToLetter(int index) 

Method Source Code

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

public class Main {
    /** Shifting index for converting column characters indexes to column numerical indexes*/
    private static final int ALPHABET_SHIFT_INDEX = (int) 'a' - 1;

    /**//from   w w  w  .j a  va  2 s .  c o m
     * Returns the 0-indexed String index correlating to the given integer index
     * 
     * @param index integer index to convert
     * @return the 0-indexed String index correlating to the given integer index
     */
    public static String intToLetter(int index) {
        index += 1;
        String str = "";
        int r = index % 26;
        do {
            str = iIntToLetter(r) + str;
            index /= 26;
            r = index % 26;
        } while (r != 0);

        return str;
    }

    /**
     * Internal conversion from int to letter 
     * 
     * @param letterIndex to convert to a letter
     * @return String containing the letter that was indexed
     */
    private static String iIntToLetter(int letterIndex) {
        if (letterIndex == 0) {
            letterIndex += 26;
        }
        String str = "" + (char) (letterIndex + ALPHABET_SHIFT_INDEX);
        return str.toUpperCase();
    }
}

Related

  1. intToGoodBadSimple(int i)
  2. intToID(int ID)
  3. intToInteger(int[] array)
  4. intToIntegerArray(int[] array)
  5. intToLengthHexByte(int args, int hexLength)
  6. intToLex(int v)
  7. intToLittleEndian(int val)
  8. intToLittleEndian(int value)
  9. intToMCInts(int i)