Transfer alphabet to a table column

0

Good morning

The problem is simple but I still can not find the right way to start programming since I do not have much time to devote to programming. The question is the following ...

As I can generate an alphabet array to insert it in the columns of my table, the code where the parameters are entered is as follows.

//GENERA LAS COLUMNAS DE LA TABLA
private List<ColumnHeaderModel> getColumnHeaderList() {
    List<ColumnHeaderModel> list = new ArrayList<>();

    for (int i = 0; i < COLUMN_SIZE; i++) {
        String strTitle = "A";

        ColumnHeaderModel header = new ColumnHeaderModel(String.valueOf(i), strTitle);
        list.add(header);
    }

    return list;
}

Here the loop rotates and prints the word with the number that passes until it reaches the limit of Columns

My idea is that each count print the letter in the corresponding column starting with A = 0 until Z = 25

Will there be a better method to do this?

If I resolve it, I'll publish it

Thanks

    
asked by Ignacio_aa 26.01.2018 в 21:49
source

2 answers

2

Using the ascii code for it. Then you convert the character ascii to String.

  

"A" = 65; "a" = 97

     

"Z" = 90; "z" = 122

The code would be as follows:

//GENERA LAS COLUMNAS DE LA TABLA
private List<ColumnHeaderModel> getColumnHeaderList() {
    List<ColumnHeaderModel> list = new ArrayList<>();
    for (int i = 0; i < COLUMN_SIZE; i++) {
        // En minúscula a-z
        //String strTitle = String.valueOf(Character.toChars(i + 97)); 
        // En mayúscula A-Z
        String strTitle = String.valueOf(Character.toChars(i + 65));
        ColumnHeaderModel header = new ColumnHeaderModel(String.valueOf(i), strTitle);
        list.add(header);
    }

    return list;
}

However, there may be cases in which it follows, and exceeds 25 characters (a-z). Therefore it would be convenient to place a stop to continue the cycle.

//GENERA LAS COLUMNAS DE LA TABLA
private List<ColumnHeaderModel> getColumnHeaderList() {
    List<ColumnHeaderModel> list = new ArrayList<>();
    // En caso de que se exceda de los 25 caracteres.
    int restart = 0;
    for (int i = 0; i < COLUMN_SIZE; i++) {
        // Simplemente para que tenga un tope
        restart = (i / 25) * 25;
        // En minúscula a-z
        //String strTitle = String.valueOf(Character.toChars(i + 97 - restart)); 
        // En mayúscula A-Z
        String strTitle = String.valueOf(Character.toChars(i + 65 - restart));
        ColumnHeaderModel header = new ColumnHeaderModel(String.valueOf(i), strTitle);
        list.add(header);
    }

    return list;
}
    
answered by 26.01.2018 в 22:25
-2

In a simple way you can create an array of the elements that make up the alphabet and display them according to their index:

 String[] Abecedario = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

        for (int i = 0; i < Abecedario.length; i++) {
            System.out.println("Columna: " + i + " valor :" + Abecedario[i]);

        }
    
answered by 26.01.2018 в 22:55