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

  • SEARCH
  • Home
  • 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 8774515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:35:15+00:00 2026-06-13T18:35:15+00:00

I’m trying to print a list of network interfaces (eventually to store them in

  • 0

I’m trying to print a list of network interfaces (eventually to store them in a String array of some kind). The following code will only print the list of interfaces if the

    String[] networkInterfaces = new String[Collections.list(nets).size()];

line is not there. It will print the entire list if that single line is not there.

    Enumeration<NetworkInterface> nets = null;
    try {
        nets = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        e.printStackTrace();
    }
    System.out.println(Collections.list(nets).size());
    String[] networkInterfaces = new String[Collections.list(nets).size()];

    for (NetworkInterface netint : Collections.list(nets)) {
        System.out.println(netint.getName());
    }

Sorry for lack of tags on this question, I wasn’t sure what was appropriate. Any idea why this occurs? I’ve modified it such that the collection is saved into an ArrayList (which seems to be fine)

    ArrayList<NetworkInterface> netints = Collections.list(nets);

but I’m still curious as to why the other way didn’t work. Thanks 🙂

  • 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-06-13T18:35:17+00:00Added an answer on June 13, 2026 at 6:35 pm

    In short it’s because an Enumeration is a stateful iterator.

    The first time that you call Collections.list(nets), this library method will loop through the nets enumeration, pulling out elements until the enumeration has no more to return. This works as expected, and the returned list is as you’d expect.

    However, on the next line you call Collections.list(nets) again. This pulls all of the elements from nets, which is now exhausted, and so “correctly” creates an empty list from an enumeration with no (more) elements.

    One way to fix this problem would be to immediately convert nets into a list, and then reference that list everywhere. So you could change the start of your code to:

    List<NetworkInterface> nets = null;
    try {
        nets = Collections.list(NetworkInterface.getNetworkInterfaces());
    }
    ...
    

    And then just reference the nets list later on instead of wrapping an enumeration each time.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.