18 Java Collections and Generics Best Practices

1. Choosing the right collections

2. Always using interface type when declaring a collection

3. use generic type and diamond operator, 4. specify initial capacity of a collection if possible.

5. Prefer isEmpty() over size()

6. Do not return null in a method that returns a collection

7. do not use the classic for loop, 8. favor using foreach() with lambda expressions, 9. overriding equals() and hashcode() properly, 10. implementing the comparable interface properly, 11. using arrays and collections utility classes, 12. using the stream api on collections, 13. prefer concurrent collections over synchronized wrappers, 14. using third-party collections libraries, 15. eliminate unchecked warnings, 16. favor generic types, 17. favor generic methods, 18. using bounded wildcards to increase api flexibility, 1. choosing th e right colle ctions.

- Does it allow duplicate elements?

- Does it accept null?

- Does it allow accessing elements by index?

- Does it offer fast adding and fast removing elements?

- Does it support concurrency?

  • Java List Tutorial
  • Java Map Tutorial
  • Java Queue Tutorial
  • Java Set Tutorial

5 . Prefer isEmpty() over size()

- HashMap -> ConcurrentHashMap

- ArrayList -> CopyOnWriteArrayList

- TreeMap -> ConcurrentSkipListMap

- PriorityQueue -> PriorityBlockingQueue

- Fastutil : This library is a great choice for collections of primitive types like int or long . It’s also able to handle big collections with more than 2.1 billion elements (2^31) very well.

- Guava : This is Google core libraries for Java 6+. It contains a magnitude of convenient methods for creating collections, like fluent builders, as well as advanced collection types like HashBiMap , ArrayListMultimap , etc.

- Eclipse Collections : this library includes almost any collection you might need: primitive type collections, multimaps, bidirectional maps and so on.

- JCTools : this library provides Java concurrency tools for the JVM. It offers some concurrent data structures currently missing from the JDK such as advanced concurrent queues.

Other Java Collections Tutorial:

  • Java Stream API Tutorial
  • Understand equals and hashCode in Java
  • Understand object ordering in Java
  • How to write generic classes and methods in Java

About the Author:

practice problems on java collections

Add comment


Notify me of follow-up comments


Welcome to Java! Easy Max Score: 3 Success Rate: 97.09%

Java stdin and stdout i easy java (basic) max score: 5 success rate: 97.00%, java if-else easy java (basic) max score: 10 success rate: 91.29%, java stdin and stdout ii easy java (basic) max score: 10 success rate: 92.54%, java output formatting easy java (basic) max score: 10 success rate: 96.63%, java loops i easy java (basic) max score: 10 success rate: 97.72%, java loops ii easy java (basic) max score: 10 success rate: 97.34%, java datatypes easy java (basic) max score: 10 success rate: 93.68%, java end-of-file easy java (basic) max score: 10 success rate: 97.93%, java static initializer block easy java (basic) max score: 10 success rate: 96.20%.

Back to Explore Page

ArrayList: Exercise

Let's solve some ArrayList practice problems.

We are given an ArrayList that contains Employee objects. We need to print the following details:

Problem 1: Find employees aged over 50

All the employee names whose age is more than 50.

Problem 2: Find employees from the USA

Remove all the Employees from the List who reside in the USA.

Problem 3: Sort employees by country

Sort all the employees by country name.

Learn Java practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn java interactively, java introduction.

  • Java Hello World
  • Java JVM, JRE and JDK
  • Java Variables and Literals
  • Java Data Types
  • Java Operators
  • Java Input and Output
  • Java Expressions & Blocks
  • Java Comment

Java Flow Control

  • Java if...else
  • Java switch Statement
  • Java for Loop
  • Java for-each Loop
  • Java while Loop
  • Java break Statement
  • Java continue Statement
  • Java Arrays
  • Multidimensional Array
  • Java Copy Array

Java OOP (I)

  • Java Class and Objects
  • Java Methods
  • Java Method Overloading
  • Java Constructor
  • Java Strings
  • Java Access Modifiers
  • Java this keyword
  • Java final keyword
  • Java Recursion
  • Java instanceof Operator

Java OOP (II)

  • Java Inheritance
  • Java Method Overriding
  • Java super Keyword
  • Abstract Class & Method
  • Java Interfaces
  • Java Polymorphism
  • Java Encapsulation

Java OOP (III)

  • Nested & Inner Class
  • Java Static Class
  • Java Anonymous Class
  • Java Singleton
  • Java enum Class
  • Java enum Constructor
  • Java enum String
  • Java Reflection
  • Java Exception Handling
  • Java Exceptions
  • Java try...catch
  • Java throw and throws
  • Java catch Multiple Exceptions
  • Java try-with-resources
  • Java Annotations
  • Java Annotation Types
  • Java Logging
  • Java Assertions

Java Collections Framework

Java Collection Interface

  • Java List Interface
  • Java ArrayList
  • Java Vector
  • Java Queue Interface
  • Java PriorityQueue
  • Java Deque Interface
  • Java LinkedList
  • Java ArrayDeque
  • Java BlockingQueue Interface
  • Java ArrayBlockingQueue
  • Java LinkedBlockingQueue

Java Map Interface

  • Java HashMap
  • Java LinkedHashMap
  • Java WeakHashMap
  • Java EnumMap
  • Java SortedMap Interface
  • Java NavigableMap Interface
  • Java TreeMap
  • Java ConcurrentMap Interface
  • Java ConcurrentHashMap

Java Set Interface

  • Java HashSet
  • Java EnumSet
  • Java LinkedhashSet
  • Java SortedSet Interface
  • Java NavigableSet Interface
  • Java TreeSet
  • Java Algorithms
  • Java Iterator
  • Java ListIterator
  • Java I/O Streams
  • Java InputStream
  • Java OutputStream
  • Java FileInputStream
  • Java FileOutputStream
  • Java ByteArrayInputStream
  • Java ByteArrayOutputStream
  • Java ObjectInputStream
  • Java ObjectOutputStream
  • Java BufferedInputStream
  • Java BufferedOutputStream
  • Java PrintStream

Java Reader/Writer

  • Java Reader
  • Java Writer
  • Java InputStreamReader
  • Java OutputStreamWriter
  • Java FileReader
  • Java FileWriter
  • Java BufferedReader
  • Java BufferedWriter
  • Java StringReader
  • Java StringWriter
  • Java PrintWriter

Additional Topics

  • Java Scanner Class
  • Java Type Casting
  • Java autoboxing and unboxing
  • Java Lambda Expression
  • Java Generics
  • Java File Class
  • Java Wrapper Class
  • Java Command Line Arguments

Java Tutorials

Java Iterator Interface

The Java collections framework provides a set of interfaces and classes to implement various data structures and algorithms.

For example, the LinkedList class of the collections framework provides the implementation of the doubly-linked list data structure.

  • Interfaces of Collections FrameWork

The Java collections framework provides various interfaces. These interfaces include several methods to perform different operations on collections.

Interfaces in the Java Collections Framework

We will learn about these interfaces, their subinterfaces, and implementation in various classes in detail in the later chapters. Let's learn about the commonly used interfaces in brief in this tutorial.

The Collection interface is the root interface of the collections framework hierarchy.

Java does not provide direct implementations of the Collection interface but provides implementations of its subinterfaces like List , Set , and Queue . To learn more, visit: Java Collection Interface

Collections Framework Vs. Collection Interface

People often get confused between the collections framework and Collection Interface.

The Collection interface is the root interface of the collections framework. The framework includes other interfaces as well: Map and Iterator . These interfaces may also have subinterfaces.

Subinterfaces of the Collection Interface

As mentioned earlier, the Collection interface includes subinterfaces that are implemented by Java classes.

All the methods of the Collection interface are also present in its subinterfaces.

Here are the subinterfaces of the Collection Interface:

List Interface

The List interface is an ordered collection that allows us to add and remove elements like an array. To learn more, visit Java List Interface

Set Interface

The Set interface allows us to store elements in different sets similar to the set in mathematics. It cannot have duplicate elements. To learn more, visit Java Set Interface

Queue Interface

The Queue interface is used when we want to store and access elements in First In, First Out manner. To learn more, visit Java Queue Interface

In Java, the Map interface allows elements to be stored in key/value pairs. Keys are unique names that can be used to access a particular element in a map. And, each key has a single value associated with it. To learn more, visit Java Map Interface

In Java, the Iterator interface provides methods that can be used to access elements of collections. To learn more, visit Java Iterator Interface

  • Why the Collections Framework?

The Java collections framework provides various data structures and algorithms that can be used directly. This has two main advantages:

  • We do not have to write code to implement these data structures and algorithms manually.
  • Our code will be much more efficient as the collections framework is highly optimized.

Moreover, the collections framework allows us to use a specific data structure for a particular type of data. Here are a few examples,

  • If we want our data to be unique, then we can use the Set interface provided by the collections framework.
  • To store data in key/value pairs, we can use the Map interface.
  • The ArrayList class provides the functionality of resizable arrays.

Example: ArrayList Class of Collections

Before we wrap up this tutorial, let's take an example of the ArrayList class of the collections framework.

The ArrayList class allows us to create resizable arrays. The class implements the List interface (which is a subinterface of the Collection interface).

In the later tutorials, we will learn about the collections framework (its interfaces and classes) in detail with the help of examples.

Table of Contents

  • Interfaces of the Collections Framework

Sorry about that.

Related Tutorials

Java Tutorial

  • Java Arrays
  • Java Strings
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Spring Boot

practice problems on java collections

  • Explore Our Geeks Community

Basics of Java

  • Java Tutorial
  • Introduction to Java
  • Similarities and Difference between Java and C++
  • Setting up the environment in Java
  • Java Basic Syntax
  • Java Hello World Program
  • Differences between JDK, JRE and JVM
  • How JVM Works - JVM Architecture?
  • Java Identifiers

Variables & DataTypes in Java

  • Java Variables
  • Scope of Variables In Java
  • Java Data Types
  • Operators in Java
  • Java Arithmetic Operators with Examples
  • Java Assignment Operators with Examples
  • Java Unary Operator with Examples
  • Java Relational Operators with Examples
  • Java Logical Operators with Examples
  • Java Ternary Operator with Examples
  • Bitwise Operators in Java

Packages in Java

  • Packages In Java

Flow Control in Java

  • Decision Making in Java (if, if-else, switch, break, continue, jump)
  • Java if statement with Examples
  • Java if-else
  • Java if-else-if ladder with Examples
  • Loops in Java
  • For Loop in Java
  • Java while loop with Examples
  • Java do-while loop with Examples
  • For-each loop in Java

Jump Statements in Java

  • Continue Statement in Java
  • Break statement in Java
  • return keyword in Java
  • Arrays in Java
  • Multidimensional Arrays in Java
  • Jagged Array in Java
  • Strings in Java
  • String class in Java
  • StringBuffer class in Java
  • StringBuilder Class in Java with Examples

OOPS in Java

  • Object Oriented Programming (OOPs) Concept in Java
  • Classes and Objects in Java
  • Java Methods
  • Access Modifiers in Java
  • Wrapper Classes in Java
  • Need of Wrapper Classes in Java

Constructors in Java

  • Java Constructors
  • Copy Constructor in Java
  • Constructor Chaining In Java with Examples
  • Private Constructors and Singleton Classes in Java

Inheritance & Polymorphism in Java

  • Inheritance in Java
  • Java and Multiple Inheritance
  • Comparison of Inheritance in C++ and Java
  • Polymorphism in Java
  • Dynamic Method Dispatch or Runtime Polymorphism in Java

Method overloading & Overiding

  • Method Overloading in Java
  • Different ways of Method Overloading in Java
  • Overriding in Java
  • Difference Between Method Overloading and Method Overriding in Java

Abstraction & Encapsulation

  • Abstraction in Java
  • Abstract Class in Java
  • Difference between Abstract Class and Interface in Java
  • Encapsulation in Java
  • Interfaces in Java
  • Nested Interface in Java
  • Marker interface in Java
  • Functional Interfaces in Java
  • Comparator Interface in Java with Examples

Keywords in Java

  • List of all Java Keywords
  • Super Keyword in Java
  • final Keyword in Java
  • abstract keyword in java
  • static Keyword in Java
  • 'this' reference in Java
  • enum in Java

Exception Handling in Java

  • Exceptions in Java
  • Types of Exception in Java with Examples
  • Checked vs Unchecked Exceptions in Java
  • Java Try Catch Block
  • Flow control in try catch finally in Java
  • throw and throws in Java
  • User-defined Custom Exception in Java

Collection Framework

Collections in java.

  • Collections Class in Java
  • List Interface in Java with Examples
  • ArrayList in Java
  • Vector Class in Java
  • Stack Class in Java
  • LinkedList in Java
  • Queue Interface In Java
  • PriorityQueue in Java
  • Deque interface in Java with Example
  • ArrayDeque in Java
  • Set in Java
  • HashSet in Java
  • LinkedHashSet in Java with Examples
  • SortedSet Interface in Java with Examples
  • NavigableSet in Java with Examples
  • TreeSet in Java
  • Map Interface in Java
  • HashMap in Java
  • Hashtable in Java
  • LinkedHashMap in Java
  • SortedMap Interface in Java with Examples
  • TreeMap in Java

Multi-threading in Java

  • Multithreading in Java
  • Lifecycle and States of a Thread in Java
  • Main thread in Java
  • Java Thread Priority in Multithreading
  • Thread Pools in Java
  • Synchronization in Java
  • Method and Block Synchronization in Java
  • Importance of Thread Synchronization in Java
  • Thread Safety and how to achieve it in Java
  • Discuss(30+)

Any group of individual objects which are represented as a single unit is known as a collection of objects. In Java, a separate framework named the “Collection Framework” has been defined in JDK 1.2 which holds all the collection classes and interface in it.  In Java, Collection interface ( java.util.Collection ) and Map interface ( java.util.Map ) are the two main “root” interfaces of Java collection classes.

What You Should Learn in Java Collections?

  • Abstract List Class
  • Abstract Sequential List Class
  • Vector Class
  • Stack Class
  • LinkedList Class
  • Blocking Queue Interface
  • AbstractQueue Class
  • PriorityQueue Class
  • PriorityBlockingQueue Class
  • ConcurrentLinkedQueue Class
  • ArrayBlockingQueue Class
  • DelayQueue Class
  • LinkedBlockingQueue Class
  • LinkedTransferQueue
  • BlockingDeque Interface
  • ConcurrentLinkedDeque Class
  • ArrayDeque Class
  • Abstract Set Class
  • CopyOnWriteArraySet Class
  • EnumSet Class
  • ConcurrentHashMap Class
  • HashSet Class
  • LinkedHashSet Class
  • NavigableSet Interface
  • ConcurrentSkipListSet Class
  • SortedMap Interface
  • NavigableMap Interface
  • ConcurrentMap Interface
  • TreeMap Class
  • AbstractMap Class
  • EnumMap Class
  • HashMap Class
  • IdentityHashMap Class
  • LinkedHashMap Class
  • HashTable Class
  • Properties Class
  • How to convert HashMap to ArrayList
  • Randomly select items from a List
  • How to add all items from a collection to an ArrayList
  • Conversion of Java Maps to List
  • Array to ArrayList Conversion
  • ArrayList to Array Conversion
  • Differences between Array and ArrayList


What is a Framework?

A framework is a set of classes and interfaces which provide a ready-made architecture. In order to implement a new feature or a class, there is no need to define a framework. However, an optimal object-oriented design always includes a framework with a collection of classes such that all the classes perform the same kind of task. 

Need for a Separate Collection Framework in Java

Before the Collection Framework(or before JDK 1.2) was introduced, the standard methods for grouping Java objects (or collections) were Arrays or Vectors , or Hashtables . All of these collections had no common interface. Therefore, though the main aim of all the collections is the same, the implementation of all these collections was defined independently and had no correlation among them. And also, it is very difficult for the users to remember all the different methods , syntax, and constructors present in every collection class.  Let’s understand this with an example of adding an element in a hashtable and a vector. 

As we can observe, none of these collections(Array, Vector, or Hashtable) implements a standard member access interface, it was very difficult for programmers to write algorithms that can work for all kinds of Collections. Another drawback is that most of the ‘Vector’ methods are final, meaning we cannot extend the ’Vector’ class to implement a similar kind of Collection. Therefore, Java developers decided to come up with a common interface to deal with the above-mentioned problems and introduced the Collection Framework in JDK 1.2 post which both, legacy Vectors and Hashtables were modified to conform to the Collection Framework. 

Advantages of the Collection Framework

Since the lack of a collection framework gave rise to the above set of disadvantages, the following are the advantages of the collection framework. 

  • Consistent API: The API has a basic set of interfaces like Collection , Set , List , or Map , all the classes (ArrayList, LinkedList, Vector, etc) that implement these interfaces have some common set of methods.  
  • Reduces programming effort: A programmer doesn’t have to worry about the design of the Collection but rather he can focus on its best use in his program. Therefore, the basic concept of Object-oriented programming (i.e.) abstraction has been successfully implemented.  
  • Increases program speed and quality: Increases performance by providing high-performance implementations of useful data structures and algorithms because in this case, the programmer need not think of the best implementation of a specific data structure. He can simply use the best implementation to drastically boost the performance of his algorithm/program.

Hierarchy of the Collection Framework

The utility package, (java.util) contains all the classes and interfaces that are required by the collection framework. The collection framework contains an interface named an iterable interface which provides the iterator to iterate through all the collections. This interface is extended by the main collection interface which acts as a root for the collection framework. All the collections extend this collection interface thereby extending the properties of the iterator and the methods of this interface. The following figure illustrates the hierarchy of the collection framework. 

Hierarchy of the Collection Framework in Java

Hierarchy of the Collection Framework in Java

Before understanding the different components in the above framework, let’s first understand a class and an interface. 

  • Class : A class is a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.  
  • Interface : Like a class, an interface can have methods and variables, but the methods declared in an interface are by default abstract (only method signature, nobody). Interfaces specify what a class must do and not how. It is the blueprint of the class.

Methods of the Collection Interface

This interface contains various methods which can be directly used by all the collections which implement this interface. They are:

Interfaces that extend the Collections Interface

The collection framework contains multiple interfaces where every interface is used to store a specific type of data. The following are the interfaces present in the framework. 

1. Iterable Interface

This is the root interface for the entire collection framework. The collection interface extends the iterable interface. Therefore, inherently, all the interfaces and classes implement this interface. The main functionality of this interface is to provide an iterator for the collections. Therefore, this interface contains only one abstract method which is the iterator. It returns the 

2. Collection Interface

This interface extends the iterable interface and is implemented by all the classes in the collection framework. This interface contains all the basic methods which every collection has like adding the data into the collection, removing the data, clearing the data, etc. All these methods are implemented in this interface because these methods are implemented by all the classes irrespective of their style of implementation. And also, having these methods in this interface ensures that the names of the methods are universal for all the collections. Therefore, in short, we can say that this interface builds a foundation on which the collection classes are implemented.

3. List Interface

This is a child interface of the collection interface. This interface is dedicated to the data of the list type in which we can store all the ordered collections of the objects. This also allows duplicate data to be present in it. This list interface is implemented by various classes like ArrayList, Vector, Stack, etc. Since all the subclasses implement the list, we can instantiate a list object with any of these classes. 

For example: 

The classes which implement the List interface are as follows:

i). ArrayList

ArrayList provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. The size of an ArrayList is increased automatically if the collection grows or shrinks if the objects are removed from the collection. Java ArrayList allows us to randomly access the list. ArrayList can not be used for primitive types , like int, char, etc. We will need a wrapper class for such cases. 

Let’s understand the ArrayList with the following example:

ii). LinkedList

The LinkedList class is an implementation of the LinkedList data structure which is a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node. 

Let’s understand the LinkedList with the following example:

iii). Vector

A vector provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. This is identical to ArrayList in terms of implementation. However, the primary difference between a vector and an ArrayList is that a Vector is synchronized and an ArrayList is non-synchronized. 

Let’s understand the Vector with an example:

Stack class models and implements the Stack data structure . The class is based on the basic principle of last-in-first-out . In addition to the basic push and pop operations, the class provides three more functions empty, search, and peek. The class can also be referred to as the subclass of Vector. 

Let’s understand the stack with an example:

Note: Stack is a subclass of Vector and a legacy class. It is thread-safe which might be overhead in an environment where thread safety is not needed. An alternate to Stack is to use ArrayDequeue which is not thread-safe and has faster array implementation.

4. Queue Interface

As the name suggests, a queue interface maintains the FIFO(First In First Out) order similar to a real-world queue line. This interface is dedicated to storing all the elements where the order of the elements matter. For example, whenever we try to book a ticket, the tickets are sold on a first come first serve basis. Therefore, the person whose request arrives first into the queue gets the ticket. There are various classes like PriorityQueue , ArrayDeque , etc. Since all these subclasses implement the queue, we can instantiate a queue object with any of these classes. 

For example:

The most frequently used implementation of the queue interface is the PriorityQueue. 

Priority Queue

A PriorityQueue is used when the objects are supposed to be processed based on priority. It is known that a queue follows the First-In-First-Out algorithm, but sometimes the elements of the queue are needed to be processed according to the priority and this class is used in these cases. The PriorityQueue is based on the priority heap. The elements of the priority queue are ordered according to the natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. 

Let’s understand the priority queue with an example:

5. Deque Interface

This is a very slight variation of the queue data structure . Deque, also known as a double-ended queue, is a data structure where we can add and remove elements from both ends of the queue. This interface extends the queue interface. The class which implements this interface is ArrayDeque. Since ArrayDeque class implements the Deque interface, we can instantiate a deque object with this class. 

The class which implements the deque interface is ArrayDeque. 

ArrayDeque class which is implemented in the collection framework provides us with a way to apply resizable array. This is a special kind of array that grows and allows users to add or remove an element from both sides of the queue. Array deques have no capacity restrictions and they grow as necessary to support usage. 

Let’s understand ArrayDeque with an example:  

6. Set Interface

A set is an unordered collection of objects in which duplicate values cannot be stored. This collection is used when we wish to avoid the duplication of the objects and wish to store only the unique objects. This set interface is implemented by various classes like HashSet, TreeSet, LinkedHashSet, etc. Since all the subclasses implement the set, we can instantiate a set object with any of these classes. 

The following are the classes that implement the Set interface:

i). HashSet

The HashSet class is an inherent implementation of the hash table data structure. The objects that we insert into the HashSet do not guarantee to be inserted in the same order. The objects are inserted based on their hashcode. This class also allows the insertion of NULL elements. Let’s understand HashSet with an example:

ii). LinkedHashSet

A LinkedHashSet is very similar to a HashSet. The difference is that this uses a doubly linked list to store the data and retains the ordering of the elements. 

Let’s understand the LinkedHashSet with an example: 

7. Sorted Set Interface

This interface is very similar to the set interface. The only difference is that this interface has extra methods that maintain the ordering of the elements. The sorted set interface extends the set interface and is used to handle the data which needs to be sorted. The class which implements this interface is TreeSet. Since this class implements the SortedSet, we can instantiate a SortedSet object with this class. 

The class which implements the sorted set interface is TreeSet.    TreeSet

The TreeSet class uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided. This must be consistent with equals if it is to correctly implement the Set interface. It can also be ordered by a Comparator provided at a set creation time, depending on which constructor is used. 

Let’s understand TreeSet with an example:

8. Map Interface

A map is a data structure that supports the key-value pair for mapping the data. This interface doesn’t support duplicate keys because the same key cannot have multiple mappings, however, it allows duplicate values in different keys. A map is useful if there is data and we wish to perform operations on the basis of the key. This map interface is implemented by various classes like HashMap , TreeMap , etc. Since all the subclasses implement the map, we can instantiate a map object with any of these classes. 

The frequently used implementation of a Map interface is a HashMap. 

HashMap provides the basic implementation of the Map interface of Java. It stores the data in (Key, Value) pairs. To access a value in a HashMap, we must know its key. HashMap uses a technique called Hashing. Hashing is a technique of converting a large String to a small String that represents the same String so that the indexing and search operations are faster. HashSet also uses HashMap internally. 

Let’s understand the HashMap with an example:

Please Login to comment...

Similar read thumbnail

  • ThakurYogeshwarSingh
  • SiddharthPandey7
  • KaashyapMSK
  • Java-Collections

Please write us at contrib[email protected] to report any issue with the above content

Improve your Coding Skills with Practice


Start training on this collection. Each time you skip or complete a kata you will be taken to the next kata in the series. Once you cycle through the items in the collection you will revert back to your normal training routine.

Description Edit

Get starting with your java coding practice with these java exercises. There is a wide range of java problems to solve.

Delete This Collection

Deleting the collection cannot be undone.

Collect: kata

Loading collection data...

You have not created any collections yet.

Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.

Get started now by creating a new collection .

Set the name for your new collection. Remember, this is going to be visible by everyone so think of something that others will understand.

CS 124 Logo

Hashing : 11/29/2023

Mp debugging part 1 : 11/28/2023, mp3: course ratings : 11/27/2023, get /course/ redux : 11/17/2023, binary search : 11/16/2023, quicksort : 11/15/2023, merge sort : 11/14/2023, sorting algorithms : 11/13/2023, mp2: course activity : 11/10/2023, practice with recursion : 11/09/2023, mp debugging part 0 : 11/08/2023, mp2: api client : 11/07/2023, mp2: api server : 11/06/2023, trees and recursion : 11/03/2023, trees : 11/02/2023, recursion : 11/01/2023, mp1: filtering and search : 10/31/2023, mp1: loading and sorting : 10/30/2023, lists review and performance : 10/27/2023, linked lists : 10/26/2023, algorithms and lists : 10/25/2023, continuing mp0 : 10/24/2023, getting started with mp0 : 10/23/2023, lambda expressions : 10/20/2023, anonymous classes : 10/19/2023, practice with interfaces : 10/18/2023, implementing interfaces : 10/17/2023, using interfaces : 10/16/2023, working with exceptions : 10/13/2023, throwing exceptions : 10/12/2023, catching exceptions : 10/11/2023, references and polymorphism : 10/10/2023, references : 10/09/2023, data modeling 2 : 10/06/2023, equality and object copying : 10/05/2023, polymorphism : 10/04/2023, inheritance : 10/03/2023, data modeling 1 : 10/02/2023, static : 09/29/2023, encapsulation : 09/28/2023, constructors : 09/27/2023, objects, continued : 09/26/2023, introduction to objects : 09/25/2023, compilation and type inference : 09/22/2023, practice with collections : 09/21/2023, maps and sets : 09/20/2023, lists and type parameters : 09/19/2023, imports and libraries : 09/18/2023, multidimensional arrays : 09/15/2023, practice with strings : 09/14/2023, null : 09/13/2023, algorithms and strings : 09/12/2023, strings : 09/11/2023, functions and algorithms : 09/08/2023, practice with functions : 09/07/2023, more about functions : 09/06/2023, errors and debugging : 09/05/2023, functions : 09/01/2023, practice with loops and algorithms : 08/31/2023, algorithms : 08/30/2023, loops : 08/29/2023, arrays : 08/28/2023, compound conditionals : 08/25/2023, conditional expressions and statements : 08/24/2023, operations on variables : 08/23/2023, variables and types : 08/22/2023, welcome to cs 124 : 08/21/2023, practice with collections.

Let’s pause before moving on to get more practice with Java’s collections—the lists, maps, and sets that are so useful for solving problems. We’ll also learn how we can combine these collections together to build more interesting data structures. Let’s get started!

Nested Collections Nested Collections

In the past lessons we’ve seen how to create and use several standard Java collections: List s, Map s, and Set s:

These collections are quite useful on their own! However, they can also be combined to great effect. Let’s see an example.

practice problems on java collections

Lists of Maps of Sets Lists of Maps of Sets

You can combine List s, Map s, and Set s in many interesting ways to build data structures to solve problems. You can create List s of Map s:

Or Set s of List s:

But generally , it’s more common for the top-level data structure to be a Map : Map s of Map s, Map s of List s, and Map s of Sets . We’ll get some practice working with these on this lesson’s practice and homework problems.

Lists to Map Warm-Up Lists to Map Warm-Up

We’ll spend the rest of the lesson working on some problems that test our understanding of how to nest collections. First, we’re asked to parse a List<String> into a Map<Set<String>> . Let’s do an example of that together, which you can use as a starting point for the practice problem that follows.

Write a method called sectionListsToMap that, given a List of String s, parses it into a Map<String, Set<String>> as follows. Each String in the passed list contains a comma-separated list of names of people in a discussion section. The first name is the section leader, and the rest are students. Your map should map each section leader to the set of students in their section. No section leader or student will appear twice in the data set.

For example, given the String s "challen,student1", "ruisong4,student2, student3" and "friendly,student4, student5", your map would have keys "challen", "ruisong4", and "friendly". "challen" would map to a set containing "student1", "ruisong4" would map to a set containing "student2" and "student3", and so on. You should assert that the passed String is not null , but if it is not null it will have the format described above.

A few hints for approaching this problem. First, consider how to use .split and .trim appropriately to parse the input String . You should get this part to work before proceeding. Then consider when you need to create the map and each set, and how to populate them.

The imports java.util.Map , java.util.Set , java.util.HashMap , and java.util.HashSet are already provided for you. You should not need additional import statements to complete this problem.

For this problem we're expecting only a method.

You may use the following packages for this problem without import ing them: java.util.HashMap , java.util.HashSet , java.util.List , java.util.Map , java.util.Set

This problem deadline has passed, but you can continue to practice. Experiment! You will not lose credit.

A publicly-accessible version of this content is available at learncs.online .

Homework Problem Warm-Up Homework Problem Warm-Up

Today’s homework problem is a challenge! Your goal is to complete the implementation of the Hawaiian Word translator you began earlier this semester. Since this problem is more difficult than other homework problems, we’re giving you an extra day to complete it. And, at the end of the day, please remember that this is just one problem , and you have homework drops.

We’ll also get you started with a walkthrough to help you think about how to approach this problem.

Note that the problem asks you to throw an exception in certain cases, something that we have not yet covered. The walkthrough describes how to do that.

Homework : Hawaiian Words

Words from languages that we are unfamiliar with can be difficult to pronounce correctly. Phonetic pronunciation guides can help make them more accessible to us. For this problem, you will write a program that produces phonetic pronunciations for Hawaiian words.

Write a method getPronunciation that accepts a single String containing a potential Hawaiian word and returns a String containing the pronunciation guide. If the passed String is null or invalid, throw an IllegalArgumentException .

Hawaiian Characters

There are 12 valid characters in the Hawaiian language: a, e, i, o, u, p, k, h, l, m, n, and w. Each Hawaiian word passed into our program must be inspected to ensure it contains only these characters, because if it does not, then we don’t have a valid Hawaiian word. If the passed word is not valid, throw an IllegalArgumentException . Note that you do not need to handle spaces or any other characters. You should ignore case when examining the input String , but your pronunciation guide output String should be all lowercase.

The consonants in the Hawaiian language are pronounced similarly to the English versions. The only exception is 'w', which is pronounced as a "v" if it follows an 'i' or 'e' and pronounced as "w" otherwise.

The vowels in the Hawaiian language are a, e, i, o, and u:

  • 'a' sounds like "ah" like "aha"
  • 'e' sounds like "eh" like "egg"
  • 'i' sounds like "ee" like "bee"
  • 'o' sounds like "oh" like "obey"
  • 'u' sounds like "oo" like "mood"

Vowel groups are also present in the Hawaiian language. More complex words can have many vowels that when grouped together require additional rules. This means we can't simply replace all 'a's with "ah", and so on.

We will consider the following simplification of the Hawaiian vowel groups for this problem:

  • "ai" and "ae" sound like "eye"
  • "ao" and "au" sound like "ow"
  • "ei" sounds like "ay"
  • "eu" sounds like "eh-oo"
  • "iu" sounds like "ew"
  • "oi" sounds like "oy"
  • "ou" sounds like "ow"
  • "ui" sounds like "ooey"

Here are a few examples used by the test suite:

  • aloha: ah-loh-hah
  • keikikane: kay-kee-kah-neh
  • iwa: ee-vah
  • MaHALO: mah-hah-loh

Note that the testing process will start by testing "w", then move on to single vowels, then test vowel groups, and then proceed to more complicated inputs, some of which will be invalid. So you can design your solution incrementally following the progression of the test suites.

A few hints to help you get started.

One way to proceed is to examine each character in the input String and build up the pronunciation guide from an empty String as you go. However, for this to work, some rules need access to the previous character (like 'w') and others to the next character (vowel groups), so it may be helpful to record the current character as well as the previous and next characters inside your loop. Doing this safely requires some care, given that the previous and next character are not always valid depending on where you are in the String .

Usually you'll want to consume one character at a time. But when you find a vowel group, you'll need to make sure you skip the next character. For example, given the input "ai", you'll need to make sure you output only "eye" and not "eye-ee" or "ah-ee".

Finally, take care to insert dashes in the correct places. A pronunciation should never end in a dash. You can avoid this by keeping track of where you are inside the loop, but it may be simpler to simply detect if your pronunciation ends with a dash and remove it before returning.

You may use the following packages for this problem without import ing them: java.util.Map , java.util.HashMap , java.util.Set , java.util.HashSet

CS People: Dina Katabi CS People: Dina Katabi

Very few people can make a legitimate claim to the label “genius”. Dina Katabi is one of them. A full professor at MIT , her groundbreaking work on wireless networking and other topics has also earned her a MacArthur Fellowship , the substantial financial award unofficially known as the “Genius Grant”.

In this video she discusses some of her work, including the ability to use wireless signals is a way that you may find quite surprising:

More Practice

Need more practice? Head over to the practice page .

Java Collections Test

Report this question.

Javatpoint Logo

Java Tutorial

Control statements, java object class, java inheritance, java polymorphism, java abstraction, java encapsulation, java oops misc.


  • Send your Feedback to [email protected]

Help Others, Please Share


Learn Latest Tutorials

Splunk tutorial


Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial



Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h [email protected] , to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • Graphic Designing
  • Digital Marketing
  • On Page and Off Page SEO
  • Content Development
  • Corporate Training
  • Classroom and Online Training

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected] . Duration: 1 week to 2 week

RSS Feed

Cave Writing Magazine


Soul Collection Services - Chapter Three

Content warning: blood drinking, death, romance .      .

          “Turn me.” The words rang through Ezra’s head. This was all her fault. She just wanted to spend more time with Wren, and it turned out poorly. She suspected that Bane was so insistent on Wren dying because of her feelings for them. She should have known that he would be possessive. Everything was a game to Bane – while he attempted to care for people, they all ended up as a pawn on his chessboard. That was part of the reason why Ezra broke up with him.

          Maybe he was jealous. Ezra hoped he would not do anything rash when she turned Wren. The thought sent another pang through her stomach. In her seven hundred odd years of existence, she had never turned a human being before. But this was Wren. If they did not want her after this, she would respect that. They would go back to just being coworkers, only seeing each other when necessary. Ezra would permanently work back in her office and stop bothering them if they did not care for her in the way she does for them.

          “Ezra?” Wren said. They looked down at her, their eyes wide and pleading. She could tell they did not want to die. Ezra did not know if that meant they wanted to become a vampire, but the options presented to them were difficult to choose between. Ezra knew that she would have never chosen this frozen existence if she had the chance. But this was Wren. They could make the decision for themself.

          Ezra took in a deep breath that she did not need and said, “Yes. I will turn you.” She squeezed their hand and moved in close, ignoring Bane’s gaze as her body brushed theirs .

          “I’ve never actually seen a turning take place. First time for everything, right Ez?” Bane said, hands under his chin as he studied the two of them.

          “Do not call me that, Bane. I will not forget that it is you who is forcing us into this situation. The least you could do is avert your eyes as we do this.”

          Bane huffed a laugh, then said, “Fine, I’ll give you your privacy. Let me know when it’s done and we can all get out of here.”

             Bane turned around, and walked through a doorway across the room, disappearing out of view. The sound of his footfalls followed him, getting softer as he moved further away.

             Wren looked around at the desolate surroundings, then said, “I’m glad that he’s not the one killing me. This isn’t ideal, but I’m glad it’s you.”

             Ezra just hummed, placing a hand on their neck. They tilted their head to the side, giving her more room. Ezra’s fingers framed their jugular, taking another breath in through deflated lungs. Wren’s scent caused her fangs to begin producing venom. The venom would be a numbing agent, working quickly to subdue Wren. Ezra would drink their blood, then she would give her own brackish blood to Wren to ingest. The combination of the venom and her blood would kill them, ensuring the change would take place. Ezra leaned in, her fangs faintly tracing Wren’s skin. Their bodies were pressed close together, and the warmth she felt from them made her hesitate for a moment.

          As she paused, Wren spoke up. “Can you… before you do this, before you turn me, can I kiss you?”

          Ezra felt a flash of heat run through her cold body. She pulled back to look at Wren. Their eyes were still wide, but their gaze became lidded as they focused on her lips. Ezra’s lips quirked, fangs getting in the way of a true smile. Wren did want her. That could change after they were turned, but Ezra dismissed the thought as she leaned in. Wren tilted their head down and their lips met. Ezra was again taken aback by the warmth that met her. She wanted more of it. The rhythm of their lips was choppy until she lifted her hands, landing at Wren’s neck, pulling them closer to her. Their hands tightened around her waist. The confidence that Wren exuded surprised her. The tip of a tongue brushed against her bottom lip. She felt the sensation across her fang and jumped. Leaning back, she watched as a flush overtook Wren’s face, and she smiled up at them for a moment.

          She leaned back, making direct eye contact, “I am going to start now, Wren.”

          Wren visibly swallowed, “Alright.”

          Ezra leaned in, watching as Wren tilted their neck again. She found the jugular vein, and without further hesitation, sank her fangs in. Blood filled her mouth, hot and pulpy. It was thick and metallic, coating her tongue and sliding down her throat. She needed to mostly drain Wren. Ezra had to stop herself before they died so that they could drink from her, too. She drank, swallowing mouthfuls of blood. Wren’s grip on her waist loosened, before falling away entirely. They swayed on their feet, but Ezra held them upright and close. Before they faded away entirely, Ezra pulled herself away, licking over the wounds she made. The punctures would close soon with the help of the venom still flooding her mouth.

          She looked at Wren. They looked weak, faint. She looked down at her wrist, and took a steadying breath, filling her deflated lungs. She brought her arm to her mouth, biting down to puncture the skin. White-hot pain erupted from her wrist as her brown blood spewed forth.

          She lifted her arm to their mouth, “Drink.”

          “Wh – What?”

          “You need to drink my blood to complete the turning.”

          Wren blinked a few times, then wrapped their hands around her arm. They brought their mouth to the seeping wounds and began to drink. A shock went through Ezra’s body. The sensation – her eyes started to flutter shut as pleasure filled her body. She breathed in; Wren’s scent still filled the air, tinged with the iron tang of blood. She felt Wren move closer to her, and her eyes opened, gazing up at the almost hungry look on their face. She moved them away from her arm, resting a hand on their cheek.

          “The turning will happen quickly. You will fall asleep and  awake changed.”

          Wren nodded, the hunger fading from their eyes as Ezra lowered both of them to the dirty ground. She grimaced. This was an awful location for a turning, but not that much different from where she was changed. Wren’s lips were reddish-brown, painted in a macabre lipstick. Ezra licked her lips, knowing hers probably looked the same. Wren smiled at Ezra as they settled their head in her lap, closing their eyes. Ezra heard the crunch of glass under shoes and looked up at Bane, who was grinning. Ezra frowned and turned towards him, careful not to jostle Wren.

          “They are dying. Right on time, too,” Ezra said, “Are you satisfied? Will you let us leave after they wake up?”

          “Why, of course! I’m getting the soul I need, and you’re getting the partner of a lifetime. Or, deathtime. That was quite the kiss, you know.” At her sharp glare, he said, “I know, I lied about leaving. It’s truly just fascinating to see a human get turned.”

          “You had no right,” she ground out.

          “Actually, I did. This is my territory, my soul – my right. I had to make sure that it was a job well done, and you gave a great performance. You know, if you ever get tired of office work, you’d be welcome as a Soul Collector. Any creature of the night can do the job. Your passion, the fire you had while turning them was inspiring. I could feel the love and pure lust from here.”

          Ezra looked down, feeling warm. Probably from the fresh blood rushing through her veins. “I will keep that in mind.”

          “Make sure that you do,” Bane said, then gasped, “Oh! Here’s the soul,” he pulled out a small, circular device that glowed blue. He pressed a button on top, then held the now-open contraption towards where a silvery mist had collected above Wren’s body. The device sucked the soul in, then snapped shut, beeping three times before falling silent.

          As they waited for Wren to awaken, Bane said, “You know, since we’re here already, I can sign the Soul Collection forms. Save you the trouble of another trip.”

          Ezra looked up at him for a moment, then cast her gaze down to where Wren had been holding the file. It was loose in their hand, easy to lift out and open to the correct form. She held out the file to Bane, who pressed on the paper and, with a bluish-purple flash of light, signed the Soul Collection form. Ezra flipped to the Time of Collection section and using the pen attached to the form, filled out the time of collection as 9:47 PM. The exact time that Wren died. She closed the file with a sigh, looking down at them. She gazed at their form, haphazardly resting on the dirty floor. She looked around the room, taking in the wreckage before she was distracted by a rustle. She looked back down at Wren, who shifted again.

          “Wren?” Ezra asked. At the sound of her voice, their eyes shot open. Ezra’s brown eyes met Wren’s warm hazel. Their face looked the same, just… smoother, less fragile. It was a good look on them. “How are you feeling?” She said. Wren opened and closed their mouth a few times, as if it was dry. Ezra remembered when she first woke up after being turned – she wanted to drink the town dry. Wren was probably feeling the same.

          “I’m… good,” They rasped. “A bit thirsty.”

          Ezra laughed, “Yes, I bet. We are allowed to go,” She shot a look at Bane, “So we can get you something to drink. I use blood from blood banks – I have a few extra bags at home.”

          “What about work? Don’t we need to go back?”

          “I will call Adrar. I will let her know that you are indisposed and that I will be as well. We can go back tomorrow. Or the next day, if you would like.” 

          Ezra brushed her hand along Wren’s cheek, who smiled.

          “Yeah, that sounds good.”

          “Perfect.” She helped them stand, watching as they stumbled on their feet for a moment. “I will see you again, Bane, but I will not forget this happened. I will contact you if I feel up to seeing you again.”

          “Fine, fine. I get it. Hey, it’s nothing personal, this was just a bit of work and pleasure getting intermixed, right?” He grinned. They both just looked at him, waiting, edging towards the door. 

          “Yes, gods, you can go.” Ezra quickly grabbed Wren’s arm and pulled them toward the door. They exited the building and crossed the street. She strode forward with Wren’s arm still in her hand. She pressed them against the van door.

          “What – ?” They said.

          “This,” she said, and leaned in, slotting their lips with hers. It was everything their first kiss was not. Despite Wren’s lack of body heat, Ezra felt warmth play between their bodies where their forms met, where their lips touched. Their lips moved against each other, consuming her entirely. She let go of Wren’s arm and wrapped her hands around the back of their neck. She rose up on her toes, deepening the kiss. As she settled flat on her feet, pulling Wren’s head down with her, her hand dropped to brush the bite marks she had left on them only minutes prior. Wren made a slight noise, pulling away with a glazed expression.

          “Let’s get out of here,” Wren said. Ezra nodded, her useless heart fluttering in her chest. She was not sure what would happen now, but she was excited to find out.

          Ezra called Adrar in the van, one hand on the steering wheel as she drove. As she steered the car down the street, Wren helpfully gave directions back to Soul Collection Services. They would need to drop off the company van and keys before they could head to Ezra’s apartment. She tapped her nails against the steering wheel as she waited for Adrar to pick up.

          The line clicked and she heard Adrar sigh, “What? Where are you? You both should’ve been back ages ago.”

          “Yes, about that. There was a problem. That was solved, but it was still a problem.”

          “A problem? Please tell me you didn’t wreck the van.”

          “No! No, I just might have…”

          “What?” Adrar snapped.

          “I turned Wren. Because Bane was insistent on them being the soul used for the random collection. He would not let us go until Wren died, and I offered, well, another option,” her words were coming in a rush. She stole a glance at Wren, who was watching her speak. She gave a weak smile and turned back to the road.

          “You what?! You killed a coworker on company time?”

          “I – Yes? Bane was threatening to do terrible things to them. Truly, it would have been awful. This was the best I could do. I understand if there are any repercussions for my actions.” At this, Wren sat up, looking alarmed.

          “... This has never happened before. Gods, that’s why we never let humans work case management positions. I should’ve known something would’ve gone wrong. HR will be a bitch to deal with on this case.” There was a pause, “Did you guys finally admit your feelings for each other, or was it the most clinical turning of all time?”

          “I, well.” Ezra looked again at Wren, who was clueless to their conversation. “Sort of, if you must know. I am sure that also causes a bind in things.”

          “Yeah, but good for you guys.” She sighed, “HR will deal with the turning and the power differential between you two. That might mean position changes, but they can’t technically tell you not to be involved.”

          “Got it. I will be at Soul Collections soon to drop off the van and the key, but I need to help Wren feed for the first time. It is a… messy process. We are lucky we have not driven past any humans or else I am not sure that Wren would have been able to control themself.” She took in a breath she did not need, “We both will need the rest of today off, and perhaps tomorrow as well. Take it out of my sick time – I have plenty.” Ezra heard Adrar sigh loudly. There were typing noises on the computer as Wren directed her to turn right. Soul Collection Services was up ahead.

          “Fine. But you better be able to get all of your work done when you return.”

          Ezra grinned, “Thank you, Adrar. I will be up shortly to give you the key.” Ezra hung up and glanced over at Wren. “We have today off, and tomorrow if you need it as well. I am still so sorry that this happened to you, but we will figure out what to do with work and this situation. As well as what to do about our…” she hesitated. They kissed twice, but that does not mean Wren wanted to be with her long-term. She could figure it out later, once they got to her apartment. She pulled into the parking garage and busied herself with finding a spot. Ezra parked, letting the car run as she turned to them.

          She cleared her throat and said, “How about I take you to my car? You can rest while I run the keys up to Adrar. I do not want you running across any humans on the other floors. In your state, it would be a bloodbath.”

          Wren laughed, “I’m fine, Ezra. My throat’s just a little sore.”

          “That is what I thought, too. Before I knew it I had murdered half the town,” Ezra said. They suddenly looked sheepish. It was a familiar expression to Ezra. It made her feel more calm about leaving them alone. It meant that underneath the newly smooth features, Wren was still there. They were recognizable, but different enough for one to need to do a double-take. Ezra wondered what the reception would be like at work. If this would cause problems among the other case managers, or if they only had to worry about HR.

          Ezra shut off the car, grabbing her bag. She watched as Wren did the same; they left the van together. Her car was parked on the same level as the van, so it was a quick trip to the sleek black car eight or nine cars to the right. She unlocked it for Wren, started the car, then bent down to look at them sitting in the passenger seat.

             “I will be right back. Do not leave, no matter how much you might want to. Alright?”

             “Alright,” Wren said softly.

             Ezra shut the door with a click , turned around, and walked towards the elevators that would bring her to Adrar.

             They were driving down a quiet street, the music a soft hum above the sound of the engine. Wren was quiet in the passenger seat, looking out the window. Ezra ran through the steps of her plan for the rest of the evening.

             First: Get Wren inside without interacting with humans. She lived far enough out of the center of town that most of the people in her apartment complex were supernatural creatures, but there was a human or two that lived in the building.

             Second: Get them fed. She would eventually have to teach them how to control their thirst, but that first bag of blood was theirs, no restrictions applied. It was hard to control your thirst, especially as a newly turned vampire. Wren was showing impressive restraint already, but she did not want to assume they had control over their thirst without a little training first.

             Third: Talk about what happened. Turning was a traumatic experience. Wren died, just to be turned into something different. Something that could not go out during the day, that outlived their family, that drank blood to survive. Maybe Wren had accepted all of this, but the events of the night happened too fast for Ezra’s comfort.

             Fourth: Kiss them again. If Wren wanted to. Ezra wanted to, but if the kisses they shared were from a moment of passion or due to their death, she would respect that.

             She tapped her nails against the steering wheel, casting a quick glance over at Wren. They turned to look at her, their lips quivering up into a smile. Their fangs poked through the seam of their lips.

             Ezra turned back to the road, “So… How are you feeling?”

             “I’m feeling fine. Just a bit thirsty. It’s weird, I was looking out the window, and I’ve never seen things so clearly at night. What other things have changed now that I’ve been turned?”

             “Well, you get superior dark vision. Superhuman strength and speed. Improved senses, but worse vitals. No need to breathe, no consistent heartbeat, no warm body temperature. Tougher skin and stronger bones, but you also get a sensitivity to sunlight. A fatal sensitivity. You can still eat garlic, though. Most of us do not eat or drink anything besides blood, but you can technically consume human food if you want.” Wren nodded, looking down at their hands. Ezra spoke again, “It is not all bad. I would not have chosen this life for myself, but I am happy. I think you could be, too.”

             “Yeah. I think so, too,” they looked back over at her, drumming their fingers on their thighs.

          Ezra turned left and pulled into the parking lot of her apartment complex. She parked in her spot, shutting off the car with a sigh. They were almost to step one.

          She unbuckled and turned to Wren again, facing them entirely, “Wren. I need you to listen to me. We are going to go into my building, but there are humans that live here, too. You must not breathe until we get to my apartment. It will feel wrong, but you cannot breathe in their scent before you are fed. Okay?”


          “If it helps, you can hold my hand the entire time. It will give you something to focus on.”

          “I- yeah. That sounds good. I absolutely want to hold your hand.”

          “Oh…” Ezra felt flustered. Step four seemed a bit more likely just then. “Alright.”

          Ezra left the car and waited for Wren to do the same. They met at the rear of the car, where Ezra held out her hand for Wren to take. She looked up at them, then led the way into the building. She punched in the code to let them in the exterior door and the mailroom, then took them up the stairs to the second floor. She turned back to Wren. Their lips were pressed together in a slight frown; they looked to be concentrating on holding their breath. Ezra walked to her front door, turning the key in the lock before easing the door open.

          She ushered Wren inside before closing the door and locking it behind her. She watched Wren as they took in her space. The decor and furniture were modern, yet comfortable. The room was scattered with the little pieces of history she lived through. She was a nostalgic person, so the items displayed on her walls and shelves had all come from significant parts of her life. Wren turned to Ezra, and she could see them breathe in again. Her apartment smelled like lavender incense, so she knew the crinkling of their nose was in response to the scent taking over their senses. It took a bit to get used to – the ultra-sensitive senses, strength, and stamina that came with being a vampire. At that thought, Ezra remembered the blood bags stored in her fridge.

          “I will get the bags out, you can sit down on the couch if you want.”

          A vampire could last a week on about 500 ml of blood, or about a fourth of a bag portioned out each day. Ezra got her blood from a blood bank that sold the unusable blood they received from donors. The bacteria and viruses that infected humans did not alter the health of a vampire in any way. They were impervious to colds or other major ailments. They could be affected by substances, though. Ezra once had a friend who drank the blood of a human on shrooms, and she tripped for hours after indulging. Ezra had become careful on where she sourced her blood after that. She could handle viruses and bacteria, but she could not deal with the effects of drugs on her system. She had experimented over the years, but found that it was not for her.

          Ezra opened the fridge and pulled out a few bags for Wren. She grabbed a cup from the cupboard and turned to see that Wren had followed her into the kitchen. Their eyes were on the bags in her hand. Ezra looked up at them and handed one bag over. Wren took the bag greedily, and without a moment of hesitation, brought it up to their mouth and punctured the plastic. They drank, swallowing large mouthfuls of blood. Ezra watched their eyes close in pleasure as blood dripped down their chin. They were ravenous, emptying the bag in moments. They opened their eyes to find Ezra looking at them. Wren smiled sheepishly, wiping their chin with the back of their hand. Blood coated fangs and blunt teeth alike.

          “Sorry,” they said. “I don’t know what came over me.”

          “Sometimes, a little bloodlust gets the better of us. Now. I want you to control that feeling inside you enough that you can pour the blood in this bag into the cup and  drink it calmly. It will probably be a while before you should drink blood around others, but if you practice each time, it will get easier.”

          Ezra swapped out the bag and handed them the cup after they tore open the perforated plastic tab. They shakily poured the blood into the cup, set down the empty bag, and slowly took a sip. Ezra could see them fighting their instincts to get as much blood in them as quickly as possible; they seemed to be overcoming it. They took another sip, looking at Ezra with a proud look on their face. Ezra smiled at that, before it faded as she remembered the events of the night.

          “Do you want to sit on the couch? We can talk about what happened tonight,” Ezra said. Wren’s expression faded too as they nodded, waiting for Ezra to lead the way. Ezra walked to the black couch, sinking down onto the cushions. Wren sat next to her, leaving a foot of space between them.

          Wren took another sip from the cup and said, “I just want you to know that I don’t blame you. I know that Bane wanted to be entertained, and me dying was going to happen either way. I’m glad it happened by your hand, or… fang, rather.”

          “I appreciate that. I feel like this is all my fault. I was the one who suggested you come with me to the meeting. You would not have died if I was less selfish.”

          “Selfish? What are you talking about?”

          “I wanted you to come with me because I like your presence. I like when you are around me. I know I have acted poorly towards you in the past, but things changed when I got to know you. It was my own selfish motivations that got you in danger. I thought Bane would be welcoming, friendly even. Not manipulative and focused wholly on your demise. I know you do not blame me, but I apologize for what happened tonight. I am sorry, Wren.”

          “You don’t have to be sorry, but I forgive you. The situation wasn’t ideal, but I’m prepared to live a new life now that I’ve died. I’m not close to my family, so they don’t have to know. I just have Michael, who doesn’t care if I’m a human or not.” Wren set down the cup on the coffee table and took Ezra’s hands, “I think it’ll be okay. I know things will be rough at work, but we’ll figure it out. I like you Ezra. I want to be around you, too. I’m glad you invited me to come with you tonight.”

          Ezra was at a loss for words. She stared at Wren. Her chest felt tight, like if she spoke, the words would be brittle from the emotions building in her body. Wren searched her expression, looking for something. Ezra was not sure what they found, but a fanged smile brightened their face. With a slight laugh, they leaned down, sliding a hand onto her neck, thumb and forefinger framing where she knew her turning marks were. Wren looked her in the eye, then their gaze dropped to her parted lips. Their eyes darted back up, but fell again when Ezra brought her lips together in a smile. She leaned up, closing the distance between them and closed her eyes. Their lips met.

          It was a hungry kiss. An aching one. Wren had not finished the cup of blood, so their bloodlust was transformed into something else entirely. Their lips moved against each other, finding a rhythm that set Ezra aflame. She reached out, sliding her hands along Wren’s shoulders before bringing a hand to clutch at the nape of their neck, fingers twisting through their hair. Ezra felt their thumb brush against her bite marks and she shuddered, deepening the kiss. Wren’s hand stayed anchored under her jaw, but the other slid along her side to the small of her waist. Their grip felt strong, confident. Ezra felt weak under the attention. She pulled back on Wren’s head, separating their mouths to breathe air she did not need. Wren was also panting, looking down at Ezra like they wanted to devour her.

          She smiled up at them, then pulled them back down, continuing the motion so that they were leaning over her as she laid back against the arm of the couch. Wren’s hand slid down her throat and rested at her collarbone, where their thumb brushed back and forth over the protruding bone. Their lips met again and again. The kiss deepened again, becoming heated. Ezra settled further, pulling them on top of her. She splayed a hand down their back and fisted a hand in their hair. They kissed for a long moment, separating again to breathe each other in.

          After a few long moments, Wren sat up, pulling Ezra up with them. They smiled at her, mouth red from the friction of their lips. Ezra knew that she looked the same. She glanced down, nervous suddenly.

          “So…” they said, looking at her. She still looked down, playing with her hands. “I know we skipped a few steps, with the turning and, uh, everything, but do you maybe want to go out sometime?”

          Ezra looked up, a slow smile spreading across her face, “Yes, I would like that. I would like that a lot.”

             “Great,” they smiled, which faltered for a moment. “Now let’s just hope we don’t lose our jobs. I like working with you.”

             “I do, too,”

             Wren leaned in and wrapped an arm around Ezra. They sat quietly for a moment. Ezra leaned forward and lifted the cup of blood from the table and pressed it into their hands; a silent command to Drink passed between them with a look. Wren grabbed the cup and took a small sip. Ezra settled back into the weight of their arm, feeling content with Wren by her side. 

          Madalyn Lovejoy started writing seriously last fall. Madalyn wrote countless poems, collected them, and just published her first chapbook through Bottlecap Press. Her writing process is often just desperately cramming out the words before they escape them. When writing Soul Collection Services, they wrote, revised, and edited the work over the course of a few weeks. This is part of a larger work, with three chapters total. The first chapter sets up the main character’s work life, introduces the characters, and reveals that the main character’s rival will be their new assistant. The second chapter highlights their developing relationship and shows them leaving together to attend a meeting that results in the main character’s death. The third chapter is from the rival/love interest’s point of view, reacting to the fall out and finding comfort in the situation.

Instagram Account




  1. Top 7 Java Programming Practice Websites || Java Practice problems, Projects & Tutorial for beginner

    practice problems on java collections

  2. Java Tutorial: Practice Questions on Arrays in Java

    practice problems on java collections

  3. How to use collections in Java's Multithreading

    practice problems on java collections

  4. Java Collections Framework Explained

    practice problems on java collections

  5. Java programming: Elementary practice

    practice problems on java collections

  6. Solved 1. Write a Java program that implements and tests the

    practice problems on java collections


  1. Finally In Java21 main method got better 🥳

  2. Java Multithreading Excellence: Navigating with Concurrent Collections

  3. INCREMENT SALARY WITH EXPERIENCE YEARS IN JAVA #coding #java #javaprogramming #programming #shorts

  4. SET in Java

  5. LeetCode in Java

  6. Assignment 10


  1. Java Collection Exercises

    List of Java Collection Exercises : ArrayList Exercises [22 exercises with solution] LinkedList Exercises [26 exercises with solution] HashSet Exercises [12 exercises with solution] TreeSet Exercises [16 exercises with solution] PriorityQueue Exercises [12 exercises with solution] HashMap Exercises [12 exercises with solution]

  2. Java Collection

    Implement different operations on a ArrayList A .   Input: The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The first line of input contains an integer Q denoting the no of queries . Th

  3. Java Collection Programs

    Here is a complete list of Java Collection programs for practice: Java Program to Get the Maximum Element From a Vector Binary Search on Java Vector Java Program to Get Elements of a LinkedList LinkedList clear () Method in Java Convert an Array into Collection in Java Java Program to Change a Collection to an Array

  4. 18 Java Collections and Generics Best Practices

    1. Choosing the right collections 2. Always using interface type when declaring a collection 3. Use generic type and diamond operator 4. Specify initial capacity of a collection if possible 5. Prefer isEmpty () over size () 6. Do not return null in a method that returns a collection

  5. Solve Java

    Welcome to Java! EasyMax Score: 3Success Rate: 97.09% Solve Challenge Java Stdin and Stdout I EasyJava (Basic)Max Score: 5Success Rate: 97.00% Solve Challenge Java If-Else EasyJava (Basic)Max Score: 10Success Rate: 91.28% Solve Challenge Java Stdin and Stdout II EasyJava (Basic)Max Score: 10Success Rate: 92.54% Solve Challenge

  6. Java Collections

    Java Collections | Set 6 (Stack) | Practice | GeeksforGeeks Back to Explore Page Java provides an inbuilt object type called Stack. It is a collection that is based on the last in first out (LIFO) principle. Try this problem using Stack. Given n elements of a stack st where the first value is the bottom-most value o

  7. 40 Java Collections Interview Questions and Answers

    Example 1: ArrayList `get (index i)` is a constant-time operation and doesn't depend on the number of elements in the list. So its performance in Big-O notation is O (1). Example 2: A linear search on array or list performance is O (n) because we need to search through entire list of elements to find the element.

  8. Java Collection

    Try this problem using ArrayList. Given a ArrayList of N elements and a integer Q defining the type of query (which will be either 1 or 2) : Q = 1 includes two integers p and r. Which means insert the value r at index p in the ArrayList and print the whole updated ArrayList. Q = 2 includes one integer p.

  9. Practice

    Platform to practice programming problems. Solve company interview questions and improve your coding intellect. Courses. Tutorials. Jobs. Practice. Contests. Search. Filters. CLEAR ALL Difficulty. School. Basic ... Java-Collections ...

  10. Java Collection

    Implement different operations on a set s . Input: The first line of input contains an integer T denoting the no of test cases . Then T test cases follow. The first line of input contains an integer Q denoting the no of queries . Then in the next line are Q space separated queries . A query can be of four types

  11. How to Learn Java Collections

    The Java Collection Framework, first introduced in JDK 1.2 ( Java Development Kit 1.2 ), is an architecture made up of interfaces and classes. In simple words, it is like a skeletal structure for components that is ready to use for various programming needs. It also offers different data operations like searching, sorting, insertion, deletion ...

  12. ArrayList: Exercise

    ArrayList: Exercise Let's solve some ArrayList practice problems. We'll cover the following Problem 1: Find employees aged over 50 Problem 2: Find employees from the USA Problem 3: Sort employees by country We are given an ArrayList that contains Employee objects. We need to print the following details: Problem 1: Find employees aged over 50

  13. Java Collections

    Given only a pointer to a node to be deleted in a singly linked list. Print the whole Linked List after deletion. Input: The first line of input contains an element T, denoting the no of test cases. Then T test cases follow. Each test case contai.

  14. Java Collections Framework

    We will learn about these interfaces, their subinterfaces, and implementation in various classes in detail in the later chapters. Let's learn about the commonly used interfaces in brief in this tutorial.

  15. Collections in Java

    Practice Any group of individual objects which are represented as a single unit is known as a collection of objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the collection classes and interface in it.

  16. Java programming Exercises, Practice, Solution

    Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises. A sample solution is provided for each exercise. ... Collection [ 126 Exercises with Solution ] Strings and I/O. String [ 107 Exercises with Solution ] Input-Output-File-System [ 18 Exercises ...

  17. 800+ Java Practice Challenges // Edabit

    In the Code tab above you'll see a starter function that looks like this: public static boolean returnTrue () { } All you have to do is type return true; between the curly braces { } and then click the Check button. If you did this correctly, the button will turn re … language_fundamentals strings validation Very Easy

  18. Java Coding Practice

    Start training on this collection. Each time you skip or complete a kata you will be taken to the next kata in the series. ... Get starting with your java coding practice with these java exercises. There is a wide range of java problems to solve. Delete This Collection. Deleting the collection cannot be undone. Delete. 8 kyu.

  19. CS 124: Practice with Collections

    We'll spend the rest of the lesson working on some problems that test our understanding of how to nest collections. First, we're asked to parse a List<String>Map<Set<String>> . Let's do an example of that together, which you can use as a starting point for the practice problem that follows. s, parses it into a Map<String, Set<String>> as ...

  20. Java Collections Questions

    QUESTION 1 Topic: Java Collections Test. Which statement is true about a static nested class? It does not have access to nonstatic members of the enclosing class. You must have a reference to an instance of the enclosing class in order to instantiate it. It's variables and methods must be static.

  21. Java Exercises

    Previous Next You can test your Java skills with W3Schools' Exercises. Exercises We have gathered a variety of Java exercises (with answers) for each Java Chapter. Try to solve an exercise by editing some code, or show the answer to see what you've done wrong. Count Your Score You will get 1 point for each correct answer.

  22. Java Object Oriented Programming

    Write a Java program to create a class called "Book" with attributes for title, author, and ISBN, and methods to add and remove books from a collection. Click me to see the solution. 6. Write a Java program to create a class called "Employee" with a name, job title, and salary attributes, and methods to calculate and update salary.

  23. Java Practice Programs

    One of the best ways to learn Java is to practice writing programs. Many resources are available online and in libraries to help you find Java practice programs. When practising Java programs, it is important to focus on understanding the concepts behind the code. Don't just copy and paste code from a website or book.

  24. Soul Collection Services

    When writing Soul Collection Services, they wrote, revised, and edited the work over the course of a few weeks. This is part of a larger work, with three chapters total. The first chapter sets up the main character's work life, introduces the characters, and reveals that the main character's rival will be their new assistant.