T - The type of the list’s elementspublic class ListBuilder<T> extends Object
Lists in a single command without
extending an existing List class.| Constructor and Description |
|---|
ListBuilder()
|
ListBuilder(List<T> list)
Creates a new list builder that will populate the given list and return
it on
get(). |
| Modifier and Type | Method and Description |
|---|---|
ListBuilder<T> |
add(T element)
Adds the given element to the list.
|
ListBuilder<T> |
addAll(Collection<? extends T> elements)
Adds all elements from the given collection to the list.
|
List<T> |
get()
Returns the populated list.
|
ListBuilder<T> |
sort()
Sorts the current list contents.
|
ListBuilder<T> |
sort(Comparator<? super T> comparator)
Sorts the current list contents using the given comparator.
|
public ListBuilder<T> add(T element)
element - The element to addpublic ListBuilder<T> addAll(Collection<? extends T> elements)
elements - The elements to addpublic ListBuilder<T> sort() throws ClassCastException
Comparable interface!ClassCastException - if the list contains elements that are not mutually
comparable (for example, strings and integers).public ListBuilder<T> sort(Comparator<? super T> comparator)
comparator - The comparator to useCopyright © 2026. All rights reserved.