In JDK 8+, without using any additional libs:
Iterator<T> source = ...;
List<T> target = new ArrayList<>();
source.forEachRemaining(target::add);
Edit: The above one is for Iterator
. If you are dealing with Iterable
,
iterable.forEach(target::add);
More Related Contents:
- Java: Get first item from a collection
- How do I remove repeated elements from ArrayList?
- What are the reasons why Map.get(Object key) is not (fully) generic
- Sorting an ArrayList of objects using a custom sorting order
- Big-O summary for Java Collections Framework implementations? [closed]
- Most efficient way to increment a Map value in Java
- Spring-Data-Jpa Repository – Underscore on Entity Column Name
- Combine multiple Collections into a single logical Collection?
- Java Ordered Map
- Handling soft-deletes with Spring JPA
- Difference between Arrays.asList(array) and new ArrayList(Arrays.asList(array))
- Map.clear() vs new Map : Which one will be better? [duplicate]
- Java – generate Random range of specific numbers without duplication of those numbers – how to?
- What is the difference between iterator and iterable and how to use them?
- How to Serialize a list in java?
- Collections.emptyList() vs. new instance
- Iteration order of HashSet
- ArrayList filter [duplicate]
- Printing HashMap In Java
- Is there a no-duplicate List implementation out there?
- Why use returned instance after save() on Spring Data JPA Repository?
- Java collections convert a string to a list of characters
- Are you supposed to have one repository per table in JPA?
- Difference between Java Enumeration and Iterator
- Is there an insertion order preserving Set that also implements List?
- SpringData : is it possible to have subqueries in the Query annotation?
- When should I return the Interface and when the concrete class?
- Spring Data + JPA with multiple datasources but only one set of Repositories
- Storing different types of elements in a List in Java
- Are they any decent on-disk implementations of Java’s Map?