0

I am passing an Arraylist in a form to a jsp, i need to get the length of that array list so that I can add element to last position of that List.

After getting a response from Flown I tried the fn:length function from JSTL library but still it doesn't seem to be working.

This is what I am trying to do exactly :

<input name = "access[${fn:length(access)+1}]" type=radio value="S" ${form.access[fn:length(access)+1] == 'S'?'checked':''}>Summary Only<br><br>
<input name = "access[${fn:length(access)+1}]" type=radio value="D" ${form.access[fn:length(access)+1] == 'D'?'checked':''}>Detail Only<br><br>
<input name = "access[${fn:length(access)+1}]" type=radio value="B" ${form.access[fn:length(access)+1] == 'B'?'checked':''}>Both<br><br>
<input name = "access[${fn:length(access)+1}]" type=radio value="N" ${form.access[fn:length(access)+1] == 'N'?'checked':''}>None<br><br>

access is an ArrayList defined as :

ArrayList<String> access = new ArrayList<String>()

I am passing this arraylist through a form to a JSP and I want to add a new element to it using JSP

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ankit Jain
  • 121
  • 6

1 Answers1

-1

You can get the an ArrayList like this: let assume here is your ArrayList of string called myList,

List myList= new ArrayList<>();

you can get the size if the arrayList like this:

myList.size();

But arryList are differents from arrays. When they are initialized, the length is not specified, that is the purpose of the arraylist, since we can use them without knowing the number of element it will require.

but you can also add element inside the arrayList without knowing the lenght

myList.add("newString");

Freddy Sop
  • 117
  • 1
  • 1
  • 8