Q:

enum integer and names

can i approach a enum by values or only by names?
for example i have a robot that initialize with direction "UP"
then i want to change his direction, turning left but it will be much more convenient to deal with the numbers representing the direction instead of the Strings "UP RIGHT DOWN LEFT"...
enum class:
package Q1;

public enum Direction{
    UP(1), RIGHT(2), DOWN(3), LEFT(4);
    private final int dir;

    //constructor for Direction enum for a robot 
    private Direction(int dir){
        this.dir = dir;
    }

    //return facing direction of a robot
    public int getDirection(){
        return this.dir;
    }

    //return the direction for represented number
    public Direction getDirFromNumber(){
        return this.dir;
    }
}

Robot class:
package Q1;

public class Robot {
    static int IDGenerator = 1000;  //ID generator for class Robot
    int RoboID;                     //The ID of the robot
    Direction direction;            //The Direction the robot is facing

    //Constructor for Robot
    public Robot(Direction dir){
        this.direction = dir;
        this.RoboID = IDGenerator;
        IDGenerator++;
    }

    //Turning the robot left
    public void turnLeft(){
        if (direction.getDirection()==1)
            this.direction = Direction.LEFT;
        else this.direction
    }
}

my question is, how can I approach Direction one time by the number representing in enum and the other time with "UP RIGHT DOWN LEFT"?

A:

You are free to implement such a method.
In your case, something like
public static Direction getDirection(int number){
    return Direction.values()[number-1];
}

But why is this more convenient? The whole point of enums is to avoid magic numbers (or strings).
I think what you really want is a method on Direction that returns the Direction when you turn left or right from it.
public Direction turnLeft(){
    switch(this){
       case LEFT: return DOWN;
       case DOWN: return RIGHT;
       case RIGHT: return UP;
       case UP: return LEFT;
    }
}

