Is there away to generate Variables' names dynamically in Java?

后端 未结 10 2395
醉酒成梦
醉酒成梦 2020-11-28 14:46

Let\'s say that I need to generate variables to hold some input from the user (I don\'t know how many they are). Without using Array, ArrayList (an

10条回答
  •  余生分开走
    2020-11-28 15:21

    This is not possible, but this is a perfect candidate for using one of the java collections.

    Either use a dynamically allocated array:

    String[] arr = new String[RUNTIME_SIZE];
    

    Or a list which can change it's size during runtime:

    List list = new ArrayList();
    

提交回复
热议问题