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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:07:05+00:00 2026-06-05T12:07:05+00:00

I am getting an unexpected output from Properties.contains() … This is my code… File

  • 0

I am getting an unexpected output from Properties.contains()…

This is my code…

File file = new File("C:\\ravi\\non-existing.no");
Properties pro = System.getProperties();
pro.put("file", file);
System.out.println(pro.contains(file)); //PRINTS TRUE , AS EXPECTED

File file2 = file;
System.out.println(pro.contains(file2)); //PRINTS TRUE , AS EXPECTED

File file3 = new File("C:\\ravi\\non-existing.no");
System.out.println(pro.contains(file3)); //EXPECTED FALSE , BUT PRINTS TRUE

File file4 = new File("C:\\ravi\\non.no");
System.out.println(pro.contains(file4)); //PRINTS FALSE , AS EXPECTED

I am expecting the Properties to check for the existance of the File, however this doesn’t seem to work. Could someone please help me explain why file3 doesn’t work as I expect.

  • 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-05T12:07:07+00:00Added an answer on June 5, 2026 at 12:07 pm

    I think your problem lies here :

     pro.put("file", file);
    

    From the Java docs:

    Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty method should be used instead.

    And when you call contains() on it, according to the Java docs:

    returns true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.

    You see your problem now?

    To clarify further:

    When you do :System.out.println(pro.contains(file3)); you end up doing file.equals(file3) , hence true.

    And when you do :System.out.println(pro.contains(file4)); you end up doing file.equals(file4) , hence false.

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

Sidebar

Related Questions

I'm getting unexpected output when running following code, DateFormat df = new SimpleDateFormat(YYYY-MM-dd); Date
I'm getting unexpected results with this code: 'foo'.match(new RegExp('\bfoo\b')); // Returns null Why is
I'm getting unexpected output from the all.equal method in R, specifically the implementation for
I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public
I'm getting unexpected output from jQuery.css() ... <img src=http://placekitten.com/640/360 alt= id=original_image style=left:0px; top:0px; />
I am running this code and getting unexpected results. I expect that the loop
I am getting a syntax error for this PHP code syntax error, unexpected T_STRING
I am beginner to javascript and i am getting unexpected output here is the
Please help me out on this explode() function issue. I am getting unexpected results
I am getting an unexpected Access Violation error in the following code: program Project65;

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.