"Aquí estoy."
"Te he estado esperando aquí durante mucho tiempo".
"Eso espero. Sigamos, entonces."
"Voy a presentarles para presentarles una clase de utilidad super-duper con todas las funciones para colecciones".
"Ya estoy temblando de emoción".
"Genial. Entonces comencemos. Estos son los métodos de la clase Collections:"
Código | Explicación |
---|---|
|
Agrega los elementos pasados a la colección pasada. Este método se puede llamar convenientemente así: Collections.addList (list, 10,11,12,13,14,15) |
|
Devuelve una «cola normal» hecha a partir de un deque. |
|
Performs a binary search for the key element in the list. The list must be sorted. You can specify a comparator to compare the elements. |
|
Checks that all elements of collection c are of a certain type. Similar methods exist for List, Map, Set, and SortedSet. |
|
Copies the src list to the dest list. |
|
Checks that the collections do not contain common elements |
|
Fills list with the element obj |
|
Counts how many times object o exists in collection c |
|
Determines the index of the first occurrence of the target list within the source list. The principle is similar to String.indexOf("some string") |
|
Determines the index of the last occurrence of the target list within the source list. Similar to String.lastIndexOf("some string") |
|
Searches for the maximum number/value in a collection. How do we find the maximum of 6 numbers? Collections.max(Arrays.asList(51, 42, 33, 24, 15, 6)); |
|
Searches for the minimum value in a collection. |
|
Creates a dummy collection in which the o element appears n times. |
|
Replaces all oldVal elements in the list with newVal elements |
|
Reverses the list. |
|
Randomly shuffles the elements of the list. |
|
Returns an immutable list consisting of one passed element. Similar methods exist for Map, Set, and SortedSet. |
|
Sorts the list in ascending order. |
|
Swaps the elements of the list |
|
Wraps this collection in a synchronized counterpart. Similar methods exist for List, Map, Set, and SortedSet. |
"Whoa! Yeah, this is a whole arsenal, and I've hardly used any of it."
"Actually, this is where my lesson ends today."
"Take a look at these methods, and find the ones you are most likely to use."
"Or better yet, study them. They will be useful to you."
"Thank you, Rishi. I'll go study."
GO TO FULL VERSION