-1
   for(int i=0;i<counter;i++){
            String textbox+""i=request.getParameter("text1"+i); 
        }

i am trying to use variable name dynamically but it says that the left hand side assignment must be a variable.I don't know how to append this numbers to the variable name using double quotes ,i am a fresher to programming .

yoga
  • 1
  • 2

2 Answers2

0

I think you should use an array o Strings:

String[] textbox = new String[counter];
for(int i=0;i<counter;i++)
{
  textbox[i]=request.getParameter("text1"+i); 
}
storm87
  • 49
  • 1
  • 5
0

You can do the same with a Map like that, you'll be able to retrieve your parameters with their names, which can make more sense than just a List:

Map<String, Object> textbox = new HashMap<>();
for(int i=0;i<counter;i++) {
    String paramId = "text"+i;
    textbox.put(paramId, request.getParameter(paramId));
}

But please note this is kind of useless since the parameters in the request are already a Map. You can directly pass the map (using request.getParameterMap()) to your methods and use it later.

sjahan
  • 5,720
  • 3
  • 19
  • 42