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, 2619🔥, 0💬
Popular Posts:
What Is in Xerces-J-bin.2.12.2.zip? Xerces-J-bin.2.12.2.zip file is the distribution package ZIP fil...
JDK 17 java.management.jmod is the JMOD file for JDK 17 Management module. JDK 17 Management module ...
JDK 17 java.xml.jmod is the JMOD file for JDK 17 XML (eXtensible Markup Language) module. JDK 17 XML...
What Is mail.jar of JavaMail 1.4? I got the JAR file from javamail-1_4.zip. mail.jar in javamail-1_4...
How to download and install ojdbc7.jar for Oracle 12c R1? ojdbc8.jar for Oracle 12c R1 is a Java 7 a...