Convert number of the day of the week into String of the day

0

I need to convert the number that corresponds to the day of the week into the String of the day into Java . Ex:

0 => Monday
1 => Tuesday
    
asked by anonymous 31.08.2017 / 22:09

1 answer

10

You can use DayOfWeek for this, for example:

import java.time.DayOfWeek;

public class Main {

    public static void main (String[] args) {
        System.out.println("1 = " + DayOfWeek.of(1));
        System.out.println("2 = " + DayOfWeek.of(2));
        System.out.println("3 = " + DayOfWeek.of(3));
        System.out.println("4 = " + DayOfWeek.of(4));
        System.out.println("5 = " + DayOfWeek.of(5));
        System.out.println("6 = " + DayOfWeek.of(6));
        System.out.println("7 = " + DayOfWeek.of(7));
    }

}

See working at repl.it

You can see some more examples: DayOfWeek and Month Enums

    
31.08.2017 / 22:22