HEllo, I have a problem in creating objects.I have a userDefined object with me.I need to take it out and create a new object pointing to a new memory.I am doing this in a loop.So everytime when I came back to the loop.I should have the object I have created with me and create a new object of the same with my desired values.Can anyone please help me out in this.
Akshay Kiran
Ranch Hand
Joined: Aug 18, 2005
Posts: 220
posted
0
what do you mean take it out? is it on a file or in memory? please be more specific, better still paste your code and explain what you want to do, that should help us help you better
"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
You create a new object using the new keyword. For example:
I'm sorry that I cannot be more specific, but you haven't given me much to work with. Are you trying to create objects from a custom class or from the Java API? It works the same with both of them, but I'm just curious if you have written your own class yet. Also, it will help if you can give us some code that you have already tried. Code will sometimes illustrate what you want to do more clearly than words do.
In addition, what are you doing with these objects? Are you putting them into an array or a Collection? Or is each object a one-time use for each iteration through the loop? Some more details along these lines will greatly help us to be able to answer your question.
Here whats happening is whenever I checks for the "?" its getting replaced with the previous value inspite of creating the new object.Could you pleas help
Wagner Danda Da Silva Filho
Ranch Hand
Joined: Mar 21, 2003
Posts: 80
posted
0
Hey Renu, please use the UBB tag "CODE" for listing Java codes, then you code will be much clear in the posting. For example:
SCJP, SCWCD
Renu Radhika
Ranch Hand
Joined: Oct 21, 2005
Posts: 243
posted
0
what is UBB code?I didnt get you?
Renu Radhika
Ranch Hand
Joined: Oct 21, 2005
Posts: 243
posted
0
Hi friends, I got the solution for my problem.Even if I create a new ArrayList the members inside it will point to the same memory as the previous ArrayLIst.So I tried looping through the members in the arrayList and created a new object of each.Hope this will help someone in the future