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

后端 未结 10 2342
醉酒成梦
醉酒成梦 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:14

    Following is the way that i have implemented and helped me to fix my solution easily without much hurdles.

    // Creating the array List

    List accountList = new ArrayList(); 
    
    
    
    
    for(int k=0;k < counter;k++){
            accountList.add(k, (String)flowCtx.getValueAt("transitId"+m));
    }
    

    Iterating the loop and adding the objects into the arraylist with the index.

    //Retrieving the object at run time with the help of the index

    String a = accountList.get(i));
    

提交回复
热议问题