List
type (joe
)
A Joe List
is a Java List
, roughly equivalent to a Java ArrayList
.
Lists created using the List()
initializer can contain any kind
of Joe value; the list need not be homogeneous. Lists received from
Java code might be read-only or require a specific item type.
- list.add([index], item) → this
- list.addAll([index], collection) → this
- list.clear() → this
- list.contains(value) → Boolean
- list.containsAll(collection) → Boolean
- list.copy() → List
- list.filter(predicate) → List
- list.get(index) → value
- list.getFirst() → value
- list.getLast() → value
- list.indexOf(value) → Number
- list.isEmpty() → Boolean
- list.lastIndexOf(value) → Number
- list.map(func) → List
- list.peekFirst() → value
- list.peekLast() → value
- list.remove(value) → Boolean
- list.removeAll(collection) → Boolean
- list.removeAt(index) → value
- list.removeFirst() → value
- list.removeLast() → value
- list.reverse() → List
- list.set(index, newValue) → oldValue
- list.size() → Number
- list.sorted([comparator]) → List
- list.sublist(start, [end]) → List
- list.toString() → String
Static Methods
List.of()
List.of(items...) → List
Creates a list containing the arguments.
List Initializer
List() → List
List(other) → List
List(size, [initValue]) → List
Creates a new list as a copy of the other list, or as an empty list of the given size. The list elements will be filled with the initValue, or with null if initValue is omitted.
Methods
list.add()
list.add([index], item) → this
Adds the item to the list at the given index, which defaults to the end of the list.
list.addAll()
list.addAll([index], collection) → this
Adds all items in the collection to the list at the given index, which defaults to the end of the list.
list.clear()
list.clear() → this
Removes all items from the list.
list.contains()
list.contains(value) → Boolean
Returns true
if the list contains the value, and false
otherwise.
list.containsAll()
list.containsAll(collection) → Boolean
Returns true
if the list contains all the values in
the collection, and false
otherwise.
list.copy()
list.copy() → List
Returns a shallow copy of the list.
list.filter()
list.filter(predicate) → List
Returns a list containing the elements for which the filter predicate is true.
list.get()
list.get(index) → value
Returns the value at the given index.
list.getFirst()
list.getFirst() → value
Returns the first value in the list. It's an error if the list is empty.
list.getLast()
list.getLast() → value
Returns the last value in the list. It's an error if the list is empty.
list.indexOf()
list.indexOf(value) → Number
Returns the index of the first occurrence of the value in the list, or -1 if not found.
list.isEmpty()
list.isEmpty() → Boolean
Returns true
if the list is empty, and false
otherwise.
list.lastIndexOf()
list.lastIndexOf(value) → Number
Returns the index of the last occurrence of the value in the list, or -1 if not found.
list.map()
list.map(func) → List
Returns a list containing the items that result from applying function func to each item in this list.
list.peekFirst()
list.peekFirst() → value
Returns the first value in the list, or null if the list is empty.
list.peekLast()
list.peekLast() → value
Returns the last value in the list, or null if the list is empty.
list.remove()
list.remove(value) → Boolean
Removes the value from the list if it's present. Returns
true
if the item was removed, and false
if it was not
present
list.removeAll()
list.removeAll(collection) → Boolean
Removes all items in the list that are found in the collection.
Returns true
if any items were removed, false
otherwise.
list.removeAt()
list.removeAt(index) → value
Removes and returns the value at the given index.
list.removeFirst()
list.removeFirst() → value
Removes and returns the first value in the list. It's an error if the list is empty.
list.removeLast()
list.removeLast() → value
Removes and returns the last value in the list. It's an error if the list is empty.
list.reverse()
list.reverse() → List
Returns a reversed copy of the list.
list.set()
list.set(index, newValue) → oldValue
Puts the value at the given index, returning the oldValue at that index.
list.size()
list.size() → Number
Returns the number of items in the list.
list.sorted()
list.sorted([comparator]) → List
Returns a list, sorted in ascending order. If no comparator
is provided, the list must be a list of strings or a list
of numbers. If a comparator is given, it must be a function
that takes two arguments and returns -1, 0, 1, like
the standard Joe.compare()
function.
To sort in descending order, provide a comparator that reverses the comparison.
var list = List(1,2,3,4,5);
var descending = list.sorted(\a,b -> -compare(a,b));
list.sublist()
list.sublist(start, [end]) → List
Returns the sublist of this list that starts at start and ends before end, which defaults to the end of the list.
list.toString()
list.toString() → String
Returns the string representation of this list.