T - the element type for the listpublic class List<T>
extends java.lang.Object
implements java.lang.Iterable<T>, java.io.Serializable
| Constructor and Description |
|---|
List(T head,
List<? extends T> tail)
Creates a new list from a head and a tail.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(java.lang.Object o)
Checks if this list contains a given element
|
static <T> List<T> |
empty()
Provides the empty list for any type argument
|
boolean |
equals(java.lang.Object obj) |
static <T> List<T> |
from(java.util.Collection<T> collection)
Creates a new list from a given collection
|
T |
get(int index)
Retrieves the element at a given index
|
int |
hashCode() |
T |
head()
Returns the head of the list
|
boolean |
isEmpty()
Indicates if this is the empty list
|
java.util.Iterator<T> |
iterator() |
static <T> List<T> |
of(T... ts)
Creates a new list from an array of elements
|
List<T> |
prepend(T element)
Creates a new List with the provided element as the head and this list as
the tail
|
int |
size()
the size of the list
|
List<? extends T> |
tail()
Returns the tail of the list
|
java.lang.Object[] |
toArray() |
<Type> Type[] |
toArray(Type[] a) |
java.lang.String |
toString() |
public List(T head, List<? extends T> tail)
head - the head of the listtail - the tail. a null tail is interpreted as the empty
list.public static <T> List<T> empty()
@SafeVarargs public static <T> List<T> of(T... ts)
ts - the elements to create a list forpublic static <T> List<T> from(java.util.Collection<T> collection)
collection - the collection to convert to a listpublic boolean isEmpty()
public T head()
java.util.NoSuchElementException - this is the empty listpublic List<? extends T> tail()
java.util.NoSuchElementException - this is the empty listpublic List<T> prepend(T element)
element - the element to prependpublic int size()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic boolean contains(java.lang.Object o)
o - the element to searchtrue iff the element existspublic java.lang.String toString()
toString in class java.lang.Objectpublic T get(int index)
java.lang.IndexOutOfBoundsException - the index is out of boundspublic java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public java.lang.Object[] toArray()
public <Type> Type[] toArray(Type[] a)
Copyright © 2018. All Rights Reserved.