Why doesn't ArrayList getSize () instead of size ()?

Possible duplicate:
Access to collection size in JSP / JSTL / EL

I use ArrayList in some JSP pages. I would like to access the ArrayList as follows:

${myArrayList.size}

But since the objects must comply with the JavaBean standard, where myArrayList.getMyPropertyName()there is ${myArrayList.myPropertyName}in JSP / JSTL, the function is myArrayList.size()not available.

Is there any other class that I should use?

Update:

It's a little tricky to admit that a feature, such as getting the size of your ArrayList in JSP, is reserved only for cleaner liners, but there may be other reasons why designers chose .size()instead.getSize()

I think this is really not a problem if you have syntax support ${fn:length(myArrayList)}or ${myArrayList.getSize()}.

+5
3

: ArrayList getSize() size()?

API API Java:

"Beans -style names" ?

"Beans ", , , . , Beans JDK ; AWT , . , API- , , . , , . :

    for (Iterator i = c.iterator(); i.hasNext(); )
        System.out.println(i.next());
, . "getIterator", "hasNextElement" "getNextElement", . , "" JDK, Beans .
+11

fn:length JSTL (. docs).

fn JSP:

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

:

${fn:length(myArrayList)}
+5

EL ${collection.size()}

  • API- JavaBeans. , . . - , .
  • EL 2.2 ${fn:length(collection)}

By the way, in JSP you usually don't need size()collections - you just iterate over it. If you need to do some calculations, think about it in the servlet / controller. Of course, I agree that this is indeed sometimes used in jsp itself.

+1
source

All Articles