Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6240131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:30:43+00:00 2026-05-24T11:30:43+00:00

Often there is the need to setup an ArrayList<> . One of the constructors

  • 0

Often there is the need to setup an ArrayList<>. One of the constructors takes a collection, but there is no constructor that takes an iterator.

What if I have an iterator? Is there a way to “reach up” to the collection that offers the iterator in order to use the ArrayList<> constructor?
Specifically I have the iterator offered by PropertiesConfiguration.getKeys() which is part of org.apache.commons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:30:44+00:00Added an answer on May 24, 2026 at 11:30 am

    There’s no such thing, an Iterator‘s Collection. An Iterator can be created independently of a Collection. It can be obtained from any Iterable, or you can even create a class implementing an iterator.

    However, you can obtain an ArrayList from an Iterator by iterating it and adding its elements one by one:

    Iterator<X> it = ...;
    List<X> list = new ArrayList<X>();
    while (it.hasNext()) {
      list.add(it.next());
    }
    

    Note, however, that this cannot be done reliably for every possible iterator, since there’s the possibility that an iterator will iterate forever, thus causing an infinite loop and most probably an OutOfMemoryError.

    I’d suggest you take a look at Google Guava, an utility library from Google. It has a class called Lists, which allows you to do the following:

    Iterator<X> it = ...;
    List<X> list = Lists.newArrayList(it);
    

    The library has tons of methods extremely useful for everyday Java coding. It contains mostly everything you want but cannot find in the standard Java 6 API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often there's no need to pay any attention to implicit arguments in Scala, but
Some classes, like exceptions or templates, only need the header file (.h), often there
When make -ing under Vim, there is often a need to vimgrep the files.
There are often times that I want to execute a command on all files
When doing software development, there is often need to include confidential information in command
Twitter's Trending Topics often consist of more than just one word. But for composed
I often see that websites use more than one page to display their information,
I have an very quick/lightweight mvc action, that is requested very often and I
I have a symfony website running on the standard LAMP setup. I need to
I have an online CVS repository that I need to check code into. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.