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 5937533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:33:18+00:00 2026-05-22T15:33:18+00:00

Here is a very simple example in Java intended to print out all of

  • 0

Here is a very simple example in Java intended to print out all of the system environment variables:

http://www.devdaily.com/blog/post/java/java-how-to-print-system-env-environment-variables

The code seems pretty simple – it just iterates over the environment variables as a mapping, printing each key and value, however when I execute the code I get the following error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Type mismatch: cannot convert from element type Object to String

What is going on here? Is the example garbage or have I set up my Eclipse / JDK in a manner which prevents this from working?

FYI, I’m using Windows XP with JDK 1.6.0_24 x86 on an update version of Eclipse.

  • 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-22T15:33:18+00:00Added an answer on May 22, 2026 at 3:33 pm

    The example code is simply wrong – it does not (and never could) compile and eclipse should show that in the code.

    The problem is that Map envMap is a raw type, so envMap.keySet() is also a raw type and its elements cannot be implicitly converted to String in the enhanced for loop.

    The solution: simply change the Map definition to:

    Map<String,String> envMap = System.getenv();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a very simple Prototype example. All it does is, on window load, an
Here's a very simple example of what I see: jrunscript -f - js> var
Here's a very simple question. I have an SP that inserts a row into
My goal here is to create a very simple template language. At the moment,
I am trying to do a very simple command line library for interactive Java
Here's the very dumb way: def divisorGenerator(n): for i in xrange(1,n/2+1): if n%i ==
I'm probably missing something very obvious here. I have files with the extension .st
Here at work we have a very large application with multiple sub applications. (500
I have a very common situation here. And for years I haven't found if
Liu Chang asked a very similar question to this one here, Linux equivalent of

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.