Elements overwrites each others in Linked List

hello, my problem is mentioned as the subject.
i'm trying to add the same object into a linked list each time with different values, however it doesn't work and eventually all objects stored in the linked list become identical.
here's the sample code.
public class Object1
     private String s = null;     
     public Object1(){}
     public void setS(String s){this.s = s;}
     public String getS(){return s;}
import java.io.*;
import java.util.List;
import java.util.LinkedList;
import java.util.Collections;
public class Test
     public static void main(String[] args)
          List ll = Collections.synchronizedList(new LinkedList());
          Object1 obj1 = new Object1();
          obj1.setS("111111");          
          ll.add(obj1);
          for (int i=0; i<ll.size(); i++)
               Object1 obj2 = (Object1)ll.get(i);
               System.out.println(">>>>>before:: " + obj2.getS() + "\n");
          obj1.setS("2222222");
          ll.add(obj1);
          for (int i=0; i<ll.size(); i++)
               Object1 obj2 = (Object1)ll.get(i);
               System.out.println(">>>>>after:: " + obj2.getS());          
and the result looks like this:
before:: 111111
after:: 2222222
after:: 2222222what i really want is something like this instead:
before:: 111111
after:: 111111
after:: 2222222could any one please help
thanks in advance
cedricc

You need to understand the distinction between references and objects. You're not storing objects in the linked list, but references. All of these references point to the same object. You need to create a new object each time through the loop.

Similar Messages

  • HT3406 If I choose "restore from iTunes backup" to move everything from old phone.  Will I still be able to use the old phone for music and apps?  Can the old phone be docked up to the computer?  Or will the new and old phone overwrite each other in some

    If I choose "restore from iTunes backup" to move everything from old iphone to a new one, will I still be able to use the old phone for music and apps?  Can the old phone be docked up to that same computer every now and then?  Or will the new and old phone overwrite each other in some way?  In other words, are the two phones treated as different devices when the "restore" option is used to set up the new phone?   Thanks in advance.

    Yes, you can use the old iPhone as an iPod touch.
    Read this:
    http://support.apple.com/kb/HT3406

  • I have downloaded two albums and they have the same song on, but they keep overwriting each other?

    I have downloaded Now 84 and Bad Blood from iTunes, both these albums have the song Pompeii on it, and my iPhone will only allow me to have one version of this song on my phone, so whenever I try to re-download the song of the album it's gone missing from it just overwrites the other version.
    I have multiple versions of other songs on my iPhone with no trouble
    Thanks in advance

    It now does it with any song I have on more than one album...

  • How to place elements among each other

    hi,
    how can i place checkboxes among each other, so that i have such design:
    checkbox 1 value 1
    checkbox 2 value 2
    checkbox 3 value 3
    and so on...
    i use following component:
    <h:selectManyCheckbox>
         <f:selectItems/>
    </h:selectManyCheckbox>i've tried also these ones, but it didn't help:
    <h:selectManyCheckbox>
    <h:outputText value="<br>" escape="false"/>
         <f:selectItems/>
    <h:outputText value="<br>" escape="false"/>
    </h:selectManyCheckbox>i always get all my checkboxes in one line:
    checkbox 1 value 1 checkbox 2 value 2 checkbox 3 value 3
    Maybe i can specify the style-attribute in <h:selectManyCheckbox> to force the line break?
    anybody how already solved such problem?

    ok, i did it you say, but now i get an exception:
    Could not find component 'tom' (calling findComponent on component 'imageForm:_id19:0:_id21')
    here the code:
    fill tomahawk component with selectedItems
    <h:panelGrid columns="1" styleClass="myFont">
         <h:column>
         <t:selectManyCheckbox value="#{dataBean.selectedItems}" id="tom" onclick="this.form.submit()" layout="spread">
              <f:selectItems value="#{dataBean.items}" id="selectTomaHawkItems"/>
         </t:selectManyCheckbox>
         </h:column>
    </h:panelGrid>place tomahawk-components in dataTable
    <h:panelGrid columns="1">
         <h:column>
              <h:dataTable value="#{dataBean.myList}" binding="#{MyDataBean.htmlDataTable}">
                 <h:column>
                      <t:checkbox index="#{MyDataBean.htmlDataTable.rowIndex}" for="tom"/>
                 </h:column>
             </h:dataTable>
         </h:column>
    </h:panelGrid>and MyDataBean has following lines:
    private HtmlDataTable htmlDataTable = new HtmlDataTable();
         public HtmlDataTable getHtmlDataTable() {
              return htmlDataTable;
         public void setHtmlDataTable(HtmlDataTable htmlDataTable) {
              this.htmlDataTable = htmlDataTable;
         public int getRowIndex() {
              return htmlDataTable.getRowIndex();
         }

  • HT2736 I do not understand why the simplest of tasks do not appear next to each other in a list of links. You would think tht "Reedem" an item would be right next to "Gift" an item, burt for some reason that just does not make sense to Apple.

    I never did find the "Gift Certificate" link even thoug support said where it "should" be, and "No" Nowhere near where you would reedem them.

    mojaleski wrote:
    When I want to read something in e-mail or which I downloaded and want the font large enough for me to see and expand with my fingers...the content then doesn't resize the shape to fit on the screen and I have to keep going from left to right to left back and forth in order to read it. Seems like it should automatically become an elongated column to fit the viewing area with just less words per line. PLEASE fix this so I can enjoy reading with larger type size to accomodate my eyesight.
    Double tap the column to make it size to fit. It will make it fit the width but not make the font larger by putting less word on a line.
    Hard to make corrections as it is hit or miss to get in between letters in a word.
    Tap and hold to get the magnifying glass or better still get the iPad User Guide which is free in iBooks - it has pictures and will save me having to type so many words to try and answer your questions
    Is there no way to scroll up or down deleting as you go...so far all I can do is delete one word/line at a time, ie in forwarding e-mail and trying to get rid of the long list of other people's contacts.
    Yes, I'm replying to this on my iPad - again, much better described in the User Guide.
    Thank you
    You're welcome. But please do have a look at the iPad User Guide - it will make things clearer and you may even find something new that you didn't already know.
    Regards,
    Colin R.

  • Help: Problem With Seperate Arrays Overwriting Each Other!

    Hi,
    I have this function that randomly allocates free time to coursework blocks. This method works because I have tested numerous times and it always prints of different allocations of time every time its called.
    The problem that I have is that I have this method that called this method twice to store each different call within a separate ArrayList.
    When I make the first call the block are assigned to the array fine. But when I called it a second time to store the next result within a separate Array the first Array result are overwritten . Any body have any idea why this is happening, I have asked numerous friends and even my supervisor and he can't find anything wrong with it. Any help would be very helpful...
    Code:
    public ArrayList<CourseworkTimeBlock> courseworkAllocation(ArrayList timetable, ArrayList<CourseworkTimeBlock> cCourseworkBlocks){
              // Calculates and stores the free "time blocks" that can be used
              // to allocate coursework.
              ArrayList<Integer> freeTimeBlocks = new ArrayList<Integer>();
              freeTimeBlocks = freeBlocks(timetable);
              Random random = new Random();
              ArrayList<CourseworkTimeBlock> courseworkTimeBlocks = new ArrayList<CourseworkTimeBlock>();
              for(int i = 0; i < cCourseworkBlocks.size(); i++){
                   int allocateTo = -100;
                   int randomPoint = 0;
                   CourseworkTimeBlock courseworkBlock;
                   courseworkBlock = cCourseworkBlocks.get(i);
                   while(allocateTo < 0){
                        randomPoint = random.nextInt(freeTimeBlocks.size());
                        allocateTo = freeTimeBlocks.get(randomPoint);
                   courseworkBlock.setBlockAllocated(allocateTo);
                   courseworkTimeBlocks.add(courseworkBlock);
                   freeTimeBlocks.set(randomPoint, -1 );
              for( int i = 0; i < courseworkTimeBlocks.size(); i++){
                   System.out.println("CW: " + courseworkTimeBlocks.get(i).getBlockAllocated());
              return courseworkTimeBlocks;
         }These are the calls I make in a separate method:
    ArrayList<CourseworkTimeBlock> courseworkTimetableOne = new ArrayList<CourseworkTimeBlock>();
    ArrayList<CourseworkTimeBlock> courseworkTimetableTwo = new ArrayList<CourseworkTimeBlock>();
             courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
             courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);Edited by: ChrisUK on Mar 1, 2008 9:11 AM

    ChrisUK wrote:
    Thanks for the reply.
    In terms of the:
    courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
    courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);They are both supposed to pass in the fixedTimetable object, the reason being is that this is a timetable and is passed through in order to find it "free time" blocks.
    The courseworkTimetableOne and courseworkTimetableTwo are just different representations of how the coursework time blocks could be allocated to that given fixedtimetable. You're calling the same method with the same parameters, so both references are going to point to the same object. It's the same as if you just replaced the second line with courseworkTimetableTwo = courseworkTimetableOne.
    You've got two references pointing to the same object.
    The fact that you do this first:
    ArrayList<CourseworkTimeBlock> courseworkTimetableOne = new ArrayList<CourseworkTimeBlock>();
    ArrayList<CourseworkTimeBlock> courseworkTimetableTwo = new ArrayList<CourseworkTimeBlock>();means nothing. You create the two new ArrayLists, but then this
    courseworkTimetableOne = courseworkAllocation(fixedTimetable, courseworkBlocks);
    courseworkTimetableTwo = courseworkAllocation(fixedTimetable, courseworkBlocks);gets rid of them. The new ArrayLists you just created are lost.
    Remember when you assign to a reference variable such as courseworkTimetableOne =, all that does is copy a reference so now courseworkTimetableOne is pointing to the same object that whatever is on the RHS is pointing to.
    If you want two different lists, then either courseworkAllocation should make a copy of its internal list and return that, or else the caller should do it.
    >
    By the way what does "SSCCE" mean?[http://mindprod.com/jgloss/sscce.html|http://mindprod.com/jgloss/sscce.html]
    [http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html]

  • Publishing different Domain files overwrite each other

    Because my Domain file was to big in iWeb 1 (was 2 GB), I split it in seperate files. I had to manage the different Domainfiles by care in iWeb 1, but it works fine. The only thing what was important that each domain file dos not had the same Site name.
    After I upgraded to iWeb 2.0.1 this workflow is not working any more. Every time a change a Domain file (different Site names)the publishing action will overwrite the last published folder in my web directory.
    The only solution is now publishing every domain to a folder on my hard drive and upload this after that. This is a very time costing workflow (publish everytime 300MB over and over again). Any suggestions?

    If you go to this post..
    http://discussions.apple.com/thread.jspa?messageID=5139509&#5139509
    .. you will read a lot about this subject.
    Follow Apnewbie's comprehensive posts to see if you can find a solution to your problem.
    All these problems go away if you publish to a hosting service that will allow multiple domains!

  • [Bug] Exporting files may overwrite each other

    I think I'm seeing a bug in LR 1.3.
    If you want to export several different versions of one image and you start exporting one version while another export of the same image is already in progress, but LR didn't already create the destination file in the file system, you'll not get a warning dialogue because of a naming conflict but the second file will just overwrite the first one.
    I managed to export 6 versions of a file, i.e. have 6 exports running at one time, but in the end having just one file. Granted my computer is of the slower ones and thus it takes some time from starting the export until the destination file (jpg, psd a.s.o.) is created. But it might also happen on up-to-date systems.
    If I'm starting the second export after a file for the first one has been created, LR correctly alerts me for the name conflict and asks me what to do.
    Johannes

    > Well, don't do that!
    Of course, that's the workaround but no fix. I don't know how often one should want to do that and it was the first time for me too (though I'm not working with LR for long time).
    I'm working with a AMD Duron 1,3GHz.
    Setting that up is a manual job. Make snapshots and then select one, export, select another, export a.s.o. First I had expected to get the chance to export several snapshots at once (using the snapshotname as file name part), but that doesn't seem to be available. Then I expected to get asked if LR should create a unique file name, but it doesn't.
    It would be nice for me to start those exports and then do some other stuff until it's done. But so I've to wait each to finish until starting the next one.
    Johannes

  • Is there a way to use multiple ipods on one computer without them overwriting each other?

    i have in total 3 ipods.
    One is an the square ipod. (the one with the moving screen on the right)
    the second is an ipod shuffle (the touch screen one)
    and i just got an ipod touch. (the colorful one)
    i still use all my ipods but on my first two i use the same itunes for it. so for example, i use one ipod to download all of my music library.
    then i connect my second ipod only to download selected songs.
    but now that i have an ipod touch, one of the ipods is going to be overwritten.
    So is there a way for that not to happen?
    having a flash drive for a seperate itunes for one ipod is to much of a hassle.
    but if anyone has the answers, i would greatly appriaciate it.
    thanks! : D

    Why do you think that one will be over written?
    You can sync as many ipods/iphones/ipads as you like to one computer.  Each is different and will only sync what you select.

  • T510 display freezes or multiple windows overwrite each other

    I have a T510 shipped with Windows 7 and a Windows XP Pro reinstall with SP3 and Nvidia NVS3100M. I am having issues with the Display, both when a monitor is attached, and not.
    The display does not refresh correctly. When I try to access "All Programs" menu thru the "Start" menu, the All Programs menu displays blank(all white) and freezes the machine for 10 to 20 seconds, after which it finally displays all the programs I have installed. Once this happens, it will be ok for 10 to 15 minutes, then it will occur again. On other occasions it will partially overwrite one open window with another and even then, neither of the windows is fully displayed.
    I have tried updating the display drivers and BIOS, as well as disabling the Nvidia Control Panel. Nothing seems to fix the issue
    Regards, Jim

    Hi there @filbert26 
    Welcome to the HP Support Forums! It is a great place to find the help you need, both from other users, HP experts and other support personnel.
    I understand that you are having trouble with your display freezing, or going to black when trying to use any other operating system other than Windows Vista. I am happy to answer your question, even though it is probably not what you want to hear. 
    Unfortunately, your system was only ever sold in Windows Vista configurations, and so there are no HP customized drivers for it, for anything other than Vista. For your convenience here is the support page for your notebook:
    HP Pavilion HDX9010NR Notebook PC
    Also please check out this page, which has some information you may find to be useful.
    HP Products - What If I Don't See My Operating System?
    Malygris1
    I work on behalf of HP
    Please click Accept as Solution if you feel my post solved your issue, it will help others find the solution.
    Click Kudos Thumbs Up on the right to say “Thanks” for helping!

  • How do I prevent multiple registrants from overwriting each other's cookies?

    Here’s the problem:
    1 household, multiple users who don’t log on or off. They are learning different languages. They come to the site to register and the registration part works fine. But, because they don't properly logon and off, the cookies that are set by the first registrant are overwritten by the second and so on.  When someone returns to the site, the cookies set by the second or third registrant would take the 1st registrant to the wrong login page. Is there a standard solution for this (seemingly) obvious problem?
    Any ideas like:
    <?php if (isset) $_COOKIE[‘targ_lang’]; {
    Rename this.new $_COOKIE['targ_lang'] to $_COOKIE[‘targ_lang2’];
    ?>
    I could then read the cookies on the index.php with:
    <?php if (isset) $_COOKIE[‘targ_lang’] and (isset) $_COOKIE [‘targ_lang2’] {
    header('Location: http://www.xxx.com/a_page_displaying_both their_languages.php');
    ?>
    That page would have a
    Select your language:
    <a href"http://www.xxx.com/Login/<?php echo $_COOKIE['targ_lang']; ?>.php"><?php echo $_COOKIE['targ_lang']; ?></a>
    or:
    <a href"http://www.xxx.com/Login/<?php echo $_COOKIE['targ_lang']; ?>.php"><?php echo $_COOKIE['targ_lang']; ?></a>
    They could select their language and then go to the proper login page.
    Bearing in mine my inexact syntax, does that make sense and does it look like it would work?
    Or, back to my original question, is there a really obvious solution to the multiple user problem I'm overlooking? (as usual)
    As always,
    Thanks for your help.
    Brian

    Can a cookie name be set dynamically like that?
    So that I could have multiple users on a computer who don't log out?
    <?php setcookie("first_name", French, time(0)+3600, "/", ".cinelingua.com");
    ?>
    So first_name would be set from the registration page input field for First
    Name?
    That would be really cool.  What does that look like?

  • JTAPI and AXL interfering with each other

    This has been driving me crazy today.
    I had to write a custom callforward app, which upon setting the call forward, modifies some line properties as well (remove any pickup group that may be present).
    To set the callforward, I've been using JTAPI and I've had this operation operational for over a year in a productive environment. Now I've added the updateLine axl command, and all of a sudden, the application no longer does what it's supposed to.
    Here is what happens: via the phone interface, I enter the number I want to forward to, then send the request to my webserver. There, the forward is set via JTAPI without exceptions being thrown (since setting / removing a cfwd gets no feedback, getting an exception = it didn't work). Then, I send the updateLine for the lines I've just forwarded. It all works out nicely, the apps comes back telling the user all his calls have been forwarded to number X.
    However, no callforwarding is actually made even though JTAPI came through telling me everything was okay. However, the pickup group does get removed from the line.
    If you then try the same operation again, this time there's only the JTAPI part as the line no longer is in the pickup group, and now the operation works like as reliable as it has always done before.
    Writing a sample app is going to be a bitch because this thing isn't quite so simple (and I'm re-using a lot of class libs of other projects so I can't just send the source code of everything to cisco) so I might not open a case on this but I thought I'd let you know.. and if Cisco employees visit this forum maybe they could spare some time trying to replicate.
    Now I'm stick having to rewrite the whole callforwarding via axl which technically isn't a problem, but it's just going to take up time that wasn't forseen in this particular project :(

    In order to modify a package, the developer would need to acquire a lock on the package. So Oracle would prevent two developers from modifying a package simultaneously. It would do nothing, though, to prevent two developers from serially overwriting each other's changes. That's one of the many reasons that you use an external source control system when developing any code, including database packages.
    Justin

  • Two programers not interfering with each other

    Hello,
    I was asked this today and I did not know the answer.
    If I have two programers, which are modifying (let's say) a package at the same time and each one of them is modifying a different part of it. Does Oracle provide any method (except some verbal aggrement) to insure that these two guys will not be modifying the same thing.
    Thanx for replies.

    In order to modify a package, the developer would need to acquire a lock on the package. So Oracle would prevent two developers from modifying a package simultaneously. It would do nothing, though, to prevent two developers from serially overwriting each other's changes. That's one of the many reasons that you use an external source control system when developing any code, including database packages.
    Justin

  • How do I find the smallest element of a doubly linked list?

    I currently have a doubly link list, each node contains two datafields df1 and df2. I need to find the smallest of df2 contained in the list and swap it with index one - until the list is sorted.
    Any ideas on how to search a doubly linked list for the smallest element would be greatly appreciated, thanks for your help.
    ps: I have found methods for find an element in a list and tried to alter it to find smallest, but my dfs are objects and I am having difficulty with the comparison.
    thanks so much for your time.

    I have given some comments in your other thread and instead of finding the minimum in each scan, you can do "neighbour-swaps". This will sort the list in fewer scans.

  • Hello! I had Photoshop Elements (and some other products) installed on my Laptob, but lost them because of a system breakdown. Trying to install these programms again, I logged in to my account "my adobe" and immediately found my products listed there plu

    Hello! I had Photoshop Elements (and some other products) installed on my Laptob, but lost them because of a system breakdown. Trying to install these programms again, I logged in to my account "my adobe" and immediately found my products listed there plus a link "download here". But clicking the link didn´t start anything. Nothing happened. How can I get my prgramms installed again?

    Try using a different browser if the link did not work.
    You can also try downloading thru the following page if you can find the version(s) you need...
    Download and Installation Help -
    https://helpx.adobe.com/download-install.html

Maybe you are looking for

  • Color laserjet pro m177fw issue

    just bought this printer....printer doesn't finish 'initalizing' . when i hit the home button, it goes there momentarily then goes back to the initializing screen and the blue dot circles the hp logo nonstop. no help when i power down and power back

  • I set the reserve disk space to 6gb, then chose Autofill from a playlist, but my iPhone 4s says only 14.4 mb is available

    How can I ensure that I enough memory to take photos on my iPhone. I usually use about 1.5 gb for photos, so I set the reserve disk space to 6 gb, but then after I did an Autofill of music, my Settings said I only have 14.4 mb available (and almost t

  • Administrating Data Guard without complexity of Grid Control.  Possible?

    I wonder if someone can shed some wisdom about implementing and administrating Data Guard without the complexity of Grid Control. Don't get me wrong, I love the Data Guard feature provided by Grid Control, but installing Grid Control just for the sak

  • Catalog Loaders in ATG

    Hi All, What are the approaches to load a catalog in ATG , when the catalog data is from a external system. 1) RL 2) We need to parse the file provided by the external system and insert the data into ATG repository. What other approaches are used, an

  • AppleTV 6.0 Problems - Programmable Remote Not Working?

    Since upgrading my AppleTV to software 6.0, my MX-980 programmable remote (an IR remote) has stopped working. Anybody got any ideas? I've tried the "Learn Remote" feature - not that I needed to use this before - no luck. Thanks.