Usage of s:iterator
struts2’s s:iterator can traverse any array, collection, etc. in the data stack. Here are some simple demos:
s:iterator tag has 3 attributes:
value: the iterated collection
id: the element in the specified collection The id
status is the index of the iterated element
1:jsp page definition element writing array or list
The printed result is: 1A2A3A4A5A
2: Index usage
If specified status, each iteration data has an instance of IteratorStatus, which has the following methods
1: #status.odd Whether the current element index is an odd number of rows 2: # status.even Is the current element index even? 3: #status.count How many elements are currently iterated 5: #status.first Whether the current element is the first value="#{"1":"a","2":"b"}" 3: traverse the data stack. Simple List class, 4: Traverse 2 lists;
Line
4: #status.index Current element index, starting from 0『#status.count=#status.index+1 』
6: #status.last Whether the current element is the last
7: #status.modules(int) Modulo the number of current rows
Current index It is an odd number:
Current element value:
s:iterator>
3: Traversing the map
value can be directly defined as:
Each element is separated by . The key and value between elements are separated by colons
value can also be the java.util.Map object in the data stack
The traversal is written as follows:
key :
value:
Of course both key and value You can use java's Object
List
class Attr{String attrName;String getAttrName(){return "123";}}
Of course value can also be written as value="%{label}" label can have. The operation
label's attribute List can be written as value="%{label.list}" which is equivalent to: getLabel().getList();
List
List
The elements of these two lists are one-to-one correspondence, one attrN corresponds to one attrV
index is :
attrName is :
attrName is :

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In Java programming, the Iterator and Iterable interfaces are important tools for processing elements in collections. The Iterator interface provides methods for iterative access to collection elements, while the Iterable interface defines the iterability of the collection so that the elements in the collection can be accessed through Iterator. The close cooperation between the two provides us with a general method for traversing collection elements. Iterator interface The Iterator interface defines the following methods: booleanhasNext(): Check whether there are still elements in the collection. Enext(): Returns the next element in the collection. voidremove(): Remove the current element. Iterable

Iterator interface The Iterator interface is an interface used to traverse collections. It provides several methods, including hasNext(), next() and remove(). The hasNext() method returns a Boolean value indicating whether there is a next element in the collection. The next() method returns the next element in the collection and removes it from the collection. The remove() method removes the current element from the collection. The following code example demonstrates how to use the Iterator interface to iterate over a collection: Listnames=Arrays.asList("John","Mary","Bob");Iterator

Conceptual differences: Iterator: Iterator is an interface that represents an iterator that obtains values from a collection. It provides methods such as MoveNext(), Current() and Reset(), allowing you to traverse the elements in the collection and operate on the current element. Iterable: Iterable is also an interface, representing an iterable object. It provides the Iterator() method, which returns an Iterator object to facilitate traversing the elements in the collection. Usage: Iterator: To use Iterator, you need to first obtain an Iterator object, and then call the MoveNext() method to move to the next

Introduction to IteratorIterator is an interface in Java for traversing collections. It provides a set of methods that allow you to access elements in a collection in a sequential manner. You can use Iterator to iterate over collection types such as List, Set, and Map. Demo code: Listlist=newArrayList();list.add("one");list.add("two");list.add("three");Iteratoriterator=list.iterator();while(iter

In Java, a collection is a collection of elements that provides a unified interface and methods to store, retrieve and operate these elements. Iterator and Iterable are two important Java interfaces that provide a common mechanism for traversing collection elements. The Iterator interface defines hasNext() and next() methods for traversing collections. The hasNext() method is used to check whether there are any untraversed elements in the collection, and the next() method is used to return the current element and move it to the next element. The Iterable interface defines the iterator() method, which returns an Iterator object for traversing the elements in the collection.

Iterator interface The Iterator interface is a low-level interface in the Java collection framework for traversing collections. It defines two main methods: hasNext(): checks if there are more elements in the collection. next(): Returns the next element in the collection. The Iterator interface also defines some optional methods, such as the remove() method, which is used to remove the current element from the collection. Using the Iterator interface You can use the Iterator interface to traverse a collection using the following steps: Get the Iterator object of the collection. Use the hasNext() method to check if there are more elements in the collection. If there are more elements, use the next() method to get the next element

Interpretation of Java documentation: Detailed explanation of the usage of the iterator() method of the HashSet class. Specific code examples are required. In Java programming, HashSet is one of the commonly used collection classes. It implements the Set interface and inherits from the AbstractSet class. The iterator() method of the HashSet class is used to return an iterator object for traversing the elements in the HashSet. This article will explain in detail the usage of iterator() method of HashSet class, and

Iterator (Iterator) and Iterable object (Iterable) are two very important interfaces in the Java collection framework. They enable you to iterate over the elements in a collection without knowing the specific implementation of the collection. The Iterator interface defines methods for traversing collections, including hasNext() and next(). The hasNext() method checks if there are more elements in the collection, while the next() method returns the next element in the collection. The Iterable interface defines a method for creating an Iterator, the iterator() method. This method returns an Iterator object that can be used to iterate over the collection. The following is using Itera
