Commit 94e2948
committed
[collect] Add method to get
This change adds a new method `Collections2.getElement(Collection, int)`, which
returns the i-th element of the collection.
Unlike existing methods via Java `Stream` or `Iterable`, the method in this
change supports fast access for `ImmutableCollection`s backed by an internal
array in `O(1)` instead of `O(n)` with the existing approach.
Users can use this method to, e.g., retrieve a random element from
`ImmutableSet` (e.g., to select a random node to connect to from a pool of
nodes in a distributed system).i-th element of Collections1 parent 0fad76f commit 94e2948
File tree
2 files changed
+6
-2
lines changed- android/guava/src/com/google/common/collect
- guava/src/com/google/common/collect
2 files changed
+6
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
777 | 777 | | |
778 | 778 | | |
779 | 779 | | |
780 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
781 | 783 | | |
782 | 784 | | |
783 | 785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
767 | 767 | | |
768 | 768 | | |
769 | 769 | | |
770 | | - | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
771 | 773 | | |
772 | 774 | | |
773 | 775 | | |
| |||
0 commit comments