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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:09+00:00 2026-05-27T15:43:09+00:00

In the following example, the float value 0.5 is accessible outside of the code

  • 0

In the following example, the float value 0.5 is accessible outside of the code block in which it was add()ed:

ArrayList<Float> myFloatArray = new ArrayList<Float>();
{
    myFloatArray.add( 0.5f );
}
// Data is accessible out of the block

Can someone explain what happens in terms of object instanciation ? Why isn’t the Float object destroyed when we leave the block it was defined ? Is it equivalent to writing

myFloatArray.add( new Float(0.5f) );

The reason I am asking this is that I would like to add a time information to each float value. I thought about creating a class that would enable me to write:

myDataPointArray.add( new dataPoint( new GregorianCalendar(2011, 11, 11), 0.5f );

However, (as expected), the ArrayList is empty outside of the block the data was add()ed. I tried to make my class immutable, as I believe it may help, but it doesn’t work any better. Can someone point me the right place where this behaviour is documented ? I wasn’t able to find it and I think its goes beyond this ArrayList example.

  • 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-27T15:43:10+00:00Added an answer on May 27, 2026 at 3:43 pm

    All objects added to your ArrayList will reside in memory as long as the ArrayList is still in use.
    As for you second question, the myDataPointArray will never loose any object you have added to it unless you remove the object from the list.

    Are you sure you are not re-assigning a new ArrayList object to myDataPointArray somewhere else after the add operation?

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

Sidebar

Related Questions

Which order is the and && operator evaluated For example the following code if
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
My Model is a generic class that contains a (for example) Value property which
Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
In the following code example, I want to change the color of the Foreground
In my code i write the following line: return ((value / 120) * 1440).ToString();
After completing the following code the value of result1 and result2 variables (measured width
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Example: Suppose in the following example I want to match strings that do not
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()

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.