如何通過其特定序號返回枚舉對象的名稱值?JAVA:通過序號值返回枚舉對象名稱
這裏是我的代碼:
import java.util.*
public class Enumarating {
enum Animals {bunneh , sheep , horse , cow , supercow}
public static void main(String [] args) {
Random rand = new Random();
Animals animal;
}
}
我將定義隨機範圍爲4,讓我們說,我得到2號。然後我想打印的「馬」。 我應該使用什麼方法?
可能重複:HTTP:/ /stackoverflow.com/q/609860/2580773 –
你想要http://stackoverflow.com/a/19277247/785663 – mabi