Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
org.apache.commons.collections4.set.ListOrderedSet Example
What is org.apache.commons.collections4.set.ListOrderedSet class? How to use org.apache.commons.collections4.set.ListOrderedSet class?
✍: FYIcenter.com
org.apache.commons.collections4.set.ListOrderedSet class is a Java class
offered in commons-collections4.jar that
wraps a regular map into a special map with
a list to maintain the order of when objects are added to the set.
If an object is added to the set for a second time, it will remain in the original position in the iteration. The order can be observed from the set via the iterator or toArray methods.
The ListOrderedSet also has various useful direct methods. These include many from List, such as get(int), remove(int) and indexOf(int). An unmodifiable List view of the set can be obtained via asList().
Here is a simple example of using org.apache.commons.collections4.bag.HashBag class:
// Copyright (c) 2016-2018 FYIcenter.com
// Supports commons-collections4-4.2
// Supports commons-collections4-4.1
import java.util.Set;
import org.apache.commons.collections4.set.ListOrderedSet;
// Example of using the ListOrderedSetExample class
public class ListOrderedSetExample {
public static void main(String[] args) throws Exception {
// Create some objects
String apple = "Apple";
String orange = "Orange";
String banana = "Banana";
// Create a ListOrderedSet set
ListOrderedSet<String> set = new ListOrderedSet<String>();
// Put some objects into the ListOrderedSet set
set.add(apple);
set.add(orange);
set.add(apple);
set.add(orange);
set.add(apple);
set.add(banana);
// loop through the set as a list
for (int i=0; i<3; i++) {
String obj = set.get(i);
System.out.println(i+": " + obj);
}
}
}
You can compile and run the above example in a command window as shown below:
C:\fyicenter>\fyicenter\jdk-1.8.0\bin\javac -cp C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar ListOrderedSetExample.java C:\fyicenter>\fyicenter\jdk-1.8.0\bin\java -cp .;C:\fyicenter\commons-collections4-4.2\commons-collections4-4.2.jar ListOrderedSetExample 0: Apple 1: Orange 2: Banana
⇒ org.apache.commons.collections4.list.TreeList Example
⇐ org.apache.commons.collections4.bag.HashBag Example
2017-05-20, ∼3050🔥, 0💬
Popular Posts:
JDK 17 jdk.internal.vm.ci.jmod is the JMOD file for JDK 17 Internal VM CI module. JDK 17 Internal VM...
Commons Pool provides an Object-pooling API, with three major aspects: 1. A generic object pool inte...
What Is javaws.jar in JRE (Java Runtime Environment) 8? javaws.jar in JRE (Java Runtime Environment)...
How to read XML document with XML Schema validation from socket connections with the socket\DelayedI...
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...