Remove Object from ArrayList

Hi,
i want to remove an object from my ArrayList. The Array-List contains objects from a class like this:
public class Data {
     String id;
     String name;
     String data;
     //getters
     //setters
myArrayList.remove(myData);
This doesn't work! Why not? What is wrong?
Daniel

The ArrayList determines which element to delete by the equals() method. The default implementation of equals() tests for instance identity. So two instances of your class with absolutely identical data fields will not match! You probably just need to override the default equals() with a proper implementation and everything will work.

Similar Messages

  • Unable to remove object from arraylist

    Hello,
    I am trying to remove a few objects from an arraylist and it isnt happeneing in one loop :
                         for(int i=0;i<someList.size();i++){
                             empVo = (EmpVO)colList.get(i);
                             if(empVo.getempName().trim().equalsIgnoreCase("A") ||empVo.getempName().trim().equalsIgnoreCase("B") ||empVo.getempName().trim().equalsIgnoreCase("C") )
                                colList.remove(i);
                         }So, it doesnt remove the object all the time whenever the names of A,B or C appear, so I have to run this loop thrice so it deletes all the data pertaining to these three emp names. Then I thought may be the size of the arraylist is changing and used a temp var for the someList.size, but that doesnt work either. Could you please tell me what is going wrong ?
    Edited by: Sarvananda on Sep 3, 2010 12:10 PM
    Also, the exact test has names A to F. So say A, D and E will be deleted in the first loop, then I have to specifically sysout and see which ones were deleted and then write another loop for B,C and F. Ofcourse at the end A - F are removed. But why two loops for it

    Encephalopathic wrote:
    What if you do this using an iterator to remove items, or if you start from the top of the list and iterate down to the first item?thanks for your reply. I was just looking at the API, and stumbled on this :
    The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.Any pointers on where I could look or how I could I move from here ?
    Another question I had was, there is no efficient way to 'move' objects in an arraylist (based on their indexes), isn't it ?
    I always have to remove and add at a certain index.

  • Error removing object from cache with write behind

    We have a cache with a DB for a backing store. The cache has a write-behind delay of about 10 seconds.
    We see an error when we:
    - Write new object to the cache
    - Remove object from cache before it gets written to cachestore (because we're still within the 10 secs and the object has not made it to the db yet).
    At first i was thinking "coherence should know if the object is in the db or not, and do the right thing", but i guess that's not the case?

    Hi Ron,
    The configuration for <local-scheme> allows you to add a cache store but you cannot use write-behind, only write-through.
    Presumably you do not want the data to be shared by the different WLS nodes, i.e. if one node puts data in the cache and that is eventually written to a RAC node, that data cannot be seen in the cache by other WLS nodes. Or do you want all the WLS nodes to share the data but just write it to different RAC nodes?
    If you use a local-scheme then the data will only be local to that WLS node and not shared.
    I can think of a possible way to do what you want but it depends on the answer to the above question.
    JK

  • UnsupportedOperationException Error while removing object from List

    Hi,
    I need to remove a set of objects from List if it contains similar objects as the other one.
    Follwing is the code snippet of the above scenario...
    List selectedPaxList = new ArrayList();
    TreeSet seatAssignedPaxlist= new TreeSet();
    selectedPaxList.add("1");
    selectedPaxList.add("2");
    selectedPaxList.add("3");
    seatAssignedPaxlist.add("1");
    seatAssignedPaxlist.add("2");
    if(selectedPaxList.containsAll(seatAssignedPaxlist))
    selectedPaxList.removeAll(seatAssignedPaxlist);
    If i do this in java program it executes fine without any error.But if I do the same in JSP I am getting the following error......
    java.lang.UnsupportedOperationException
    at java.util.AbstractList.remove(AbstractList.java:167)
    at java.util.AbstractList$Itr.remove(AbstractList.java:432)
    at java.util.AbstractCollection.removeAll(AbstractCollection.java:351)
    Plz... help me to resolve the issue

    java.lang.UnsupportedOperationException
    at
    java.util.AbstractList.remove(AbstractList.java:167)
    at
    java.util.AbstractList$Itr.remove(AbstractList.java:43
    2)
    at
    java.util.AbstractCollection.removeAll(AbstractCollect
    ion.java:351)
    That stack trace looks wrong to me.
    ArrayList overrides the remove method, so it
    shouldn't be using the method in AbstractList. That's what I thought, too. There is either something missing or it's not an ArrayList. In fact the javadoc of AbstractList.remove sais:
    "This implementation always throws an UnsupportedOperationException."
    So it really looks like another subclass is used.
    Also
    the object it is trying to remove is a list (from
    your exmaple it should be a String)
    I could be wrong.These are just the code references not the parameters, I think.
    -Puce

  • How to remove objects from pics using LR...

    I am not a professional photographer and I do not have a whole lot of photo editing knowledge. I started out several years ago using Photoshop elements 5 and eventually learned how to do several things like moving objects around or removing them from a photo, or moving someone's face into a different picture if their eyes were closed and lots of nice editing features. I loved it and still love it. My laptop was getting really old and slow so I just recently purchased a new computer which has windows 8 on it. I loaded my photoshop elements and cannot get it to open or work properly and am wondering if it's because of the windows 8 operating system. So I then decided to purchase a new photo editing software. I decided (quickly.. too quickly) to purchase adobe lightroom just because it had very good reviews online. Now I have several pictures that need to be edited for Christmas and I cannot find any "lasso tool" or any thing similar right now.. I was so used to using the layers and features from the PE and now my heart is broken because I feel so lost and maybe broke at the same time!! This program is soooo different than what I was used to using but I don't even know if I can do the same things with it. EXAMPLE: there is an air conditioner unit in one of the photos I've taken and I was planning on removing it from the picture. Also I was aiming on moving a face over from another picture because of some closed eyes.. Someone please tell me, is this program capable of doing these things or can I only play with the lighting in this? Will I have to spend more of my $$ to get another Photoshop elements to get the features I use?

    These tasks are tasks for Photoshop or Photoshop Elements, not for Lightroom, which is more an image data base.

  • How can we know the affected reports when i remove object from universe

    Hi All,
    If i remove any objects from the universe.
    How can i know the list of affected reports.

    Thanks for your update.
    It shows what are all the reports has been created  by using that particular universe.
    But my question was, if i remove any object from the universe, Then what are all the reports affected(We may not use that deleted object in all the reports)

  • Removing objects from photo

    I am trialling photosup elements before deciding to buy it or not.  Not sure if there is a difference in the trial version compared to the purchased version. I am trying to remove an unwanted object from a picture by highlighting the unwanted object,  then I go to edit and then fill. However there is no option for "content aware" under the fill option as shown in the tutorial.  As a result, if I choose any of the options under the fill tab,  it will only remove the object and leave a "blank spot" on the picture.  Have I missed some steps here please?  Thank you.

    Thank you all for your advice. It certainly was amazing what you were able to do with your suggestions.  As mentioned,  I am trialling photoshop elements (before deciding it is a product that I can use with ease) and was facinated by the ease of use on the tutorials, particularly the content aware move function. If I am not mistaken, it seems to suggest it is a matter of highlighting the object to be deleted / moved, then choose the content aware move function, and photoshop will do all the 'patching' and merging of surroundings.  So basically a click of a button.  Unfortunately I couldn't find that function on the trial version of the product.  So was wondering if the function is actually available on the trial version so I can see if I can use it before resorting to other alternatives.  Thank you.

  • Remove object from TR

    Hi Expert,
    I want to remove DTP from TR , I accidently collected before I info cube and MP.Trying to stay in sequence...is there any problem if you add this object later in another TR ???
    Please advice on this.Thanks in advance
    Edited by: ramshri on Aug 18, 2011 11:50 PM

    Hi
    Just go to SE03,
    Under the folder, REQUESTS/TASK---
    Select UNLOCK Objects,
    Then ENTER your Transport Request
    Click Execute button
    Click Yes
    Then go to SE09,
    Expand the PArticular request with sign '+" on left hand side
    Then , look for the technical name as DTP_
    Select that ..by placing cursor over there, and then choose the DELETE button below the MENU option on the top of the screen where there is small ICON.
    Then again in SE09, Select the MENU Request/Task, look for the Object List which is at the last, and then expand by clicking the right arrow, and select LOCK OBJECTS from the CONTEXT MENU
    or
    Select the particular REQUEST by placing the cursor on it, and PRESS CTRL+F3
    Then you can add it another request if you want else create another etc..do as you like.
    Hope this helps you

  • Removing object from kodo datacache doesnt always work.

    Hi,
    We're using a very old version of kodo - 3.4.1 but it seems to work well.
    We seem to have come across an intermittent issue where if we remove an object from the datacache using the DataCache.commit call, then the object doesnt actually seem to get removed. So the application continues operation with the out of date cached object. We get no exception or error though.
    Has anyone see anything like this before? I can't seem to find any available known issues list or bug database for kodo, I guess this isnt available?
    Thanks,
    Dan

    The size will refer to individual DataCache size.
    KodoPersistenceManager.getDataStoreCache() or getDataStoreCache("myCache") will return the default or named datacaches respectively.
    You can evict the L2 cache content on the returned DataCache instance from the previous methods.

  • Remove object from Linkedlist?

    Hello,
    I built this function to return the object with the lowest cost variable, and remove this object from the linkedlist.
    The method does not always seem to return the object with the lowest cost. I wondered if the problem was because I removed the object being returning?
    Could anyone see the problem?
    Thanks
    Node lowestState(LinkedList list){
    Node object = (Node) list.get(0);
    int index = 0, cost = object.getCost();
    for(int i = 1; i < list.size(); i++){
    object = (Node) list.get(i);
    int testCost = object.getCost();
    if(testCost < cost){
    cost = testCost;
    index = i;
    list.remove(index);
    return object;
    }

    get() must traverse the links until it finds the given one.
    So get() behaves O(n), like the whole traversal.
    import java.util.*;
    public class llt {
    static LinkedList li = new LinkedList();
    static int LIMIT=64*1024;
    public static void main(String args[]) {
         for(int i=0;i<LIMIT;i++) li.add(new Integer(i%7 * (i%3) + (i%5)));
         for(int k=0;k<4;k++) doit();
    static void doit() {
    int i;
    int sum=0;
    long t0=System.currentTimeMillis();
         for(i=0;i<li.size();i++) {
              sum += ((Integer) li.get(i)).intValue();
    long t1=System.currentTimeMillis();
         for(ListIterator lii =li.listIterator(0);lii.hasNext();) {
              sum -= ((Integer) lii.next()).intValue();
    long t2=System.currentTimeMillis();
         System.out.println((t2-t1) + " " + (t1-t0) + " " + sum);
    0 27594 0
    0 27719 0
    0 28359 0
    0 27391 0

  • Remove element from arraylist, jstl

    HI there,
    i use bean for an array list
    <jsp:useBean id="list" scope="page" class="java.util.ArrayList"/>
    then i add element in the list
    later i need set up a loop does the following:
    remove one element from the list and process it
    until the list is empty
    is this (romoving elment from a list) possible to be done using only jstl
    thanks

    No, it is not possible.
    JSTL is for use on JSP pages.
    JSP pages are meant for "display"
    You sound like you are doing processing - this sort of stuff more properly belongs in a java class.

  • Howto remove objects from atlas

    Hello: Still getting my feet wet with ZfS7. I have setup
    three ZfS management servers, one each in our three offices.
    Each server has netexplorer setup to search it's local
    subnet. However, when I first started out I had setup the
    first management server to search all three subnets. This
    has now been fixed.
    However, I now have artifacts from this first setup. This
    is a bit hard for me to describe so be patient. IN C1 there
    is an object called ZfS_Sites. Under it are my three
    service locators, one for each office subnet. Under these
    is Atlas and under that you find the router in each office.
    My problem is the first server I setup search all three
    subnets and now therefore lists all three routers. I really
    only want to show the local router and therefore need to
    remove the other two. I just cannot figure out how to
    remove these extraneous objects.
    Can you help me out?? Chris.

    Chris,
    right-click the object, database editor, delete
    Shaun Pond

  • Error #2025:The supplied DisplayObject must be a child of the caller - Removing Object from Array

    Hi guys, I'm pretty new to as3 and I'm trying to make a game where the player supposedly clicks on the stage and 3 towers which I've spawned dynamically should shoot towards the area. Everything works in terms of tower rotation, etc, but the bullets will not be removed from the stage when I exit the level into another scene. The boundary checking is fine, too.
    Here's a part of the code in the Main.as file.
    private function clickTower1(e:MouseEvent):void
    for each (var tower1:mcTower1 in tower1Array)
    var newLaser1:mcLaser1 = new mcLaser1();
    newLaser1.rotation = tower1.rotation;
    newLaser1.x = tower1.x + Math.cos(newLaser1.rotation * Math.PI / 180) * 40;
    newLaser1.y = tower1.y + Math.sin(newLaser1.rotation * Math.PI / 180) * 40;
    newLaser1.addEventListener(Event.ENTER_FRAME, laser1Handler);
    tower1BulletArray.push(newLaser1); stage.addChild(newLaser1);
      private function laser1Handler(e:Event):void
    //Make laser move in direction of turret.
    var newLaser1:MovieClip = e.currentTarget as MovieClip;
    newLaser1.x += Math.cos(newLaser1.rotation * Math.PI / 180) * laser1Speed;
    newLaser1.y += Math.sin(newLaser1.rotation * Math.PI / 180) * laser1Speed;
    //Boundary checking if (newLaser1.x < -50 || newLaser1.x > 800 || newLaser1.y > 600 || newLaser1.y < -50)
    newLaser1.removeEventListener(Event.ENTER_FRAME, laser1Handler); stage.removeChild(newLaser1);
    tower1BulletArray.splice(0, 1);
    I have a function called exitLevel, which basically, as the name states, exits the level when a button is clicked. It worked perfectly before I started coding the bullets.
        private function exitLevel(e:MouseEvent):void
    stage.frameRate = 6;
    gamePaused = false;
    clearLevel();
    gotoAndStop(1, 'exitLevel');
    btnExitLevel.addEventListener(MouseEvent.CLICK, levelSelect1);
      private function clearLevel():void
    stage.removeEventListener(Event.ENTER_FRAME, update);
    stage.removeChild(buttonCreep1); stage.removeChild(buttonCreep2);
    for (var i = creep1Array.length - 1; i >= 0; i--)
    removeChild(creep1Array[i]);
    creep1Array.splice(i, 1);
    //trace ("Creep1 Removed");
    for (var j = creep2Array.length - 1; j >= 0; j--)
    removeChild(creep2Array[j]);
    creep2Array.splice(j, 1);
    //trace ("Creep2 Removed");
    for (var k = tower1Array.length - 1; k >= 0; k--)
    removeChild(tower1Array[k]); tower1Array.splice(k, 1);
    for (var l = tower1BulletArray.length - 1; l >= 0; l--)
      stage.removeChild(tower1BulletArray[l]);
    tower1BulletArray.splice(0, 1);
    After debugging, it says the error is at the end, where i try to remove the child from the stage. What is wrong? Sorry, I'm a beginner at as3 so any answers might have to be spoonfeeding... I'll try to learn and understand, though. Thanks!
    I did take some of the code off of a guide on the web, and I don't understand it totally, so can someone explain to me what this code does as well? What is e.currentTarget? Thanks!
    var newLaser1:MovieClip = e.currentTarget as MovieClip;
    Here's the full .as file if anybody wants to take a look. http://pastebin.com/5ff4BQa5

    Hi, I managed to solve the errors (kind of) by using this code.
    for (var i:int = tower1BulletArray.length - 1; i >= 0; i--)
    if (tower1BulletArray.parent)
    tower1BulletArray[l].parent.removeChild(tower1BulletArray[l]);
    tower1BulletArray.splice(i, 1);
    However, the problem still persists that the bullets stay in the screen after I change the scene. Any solution? Thanks!

  • Problem removing Objects from the stage in Flash CS4 (AS3.0)

    I have a problem with this code:
    this.addEventListener(Event.ENTER_FRAME, vanish);
    function vanish(event:Event):void{
         if(character_mc.hitTestObject(vanish_mc)){
              vanish_mc.parent.removeChild(vanish_mc);
    There are two overlapping objects on my stage: character_mc and vanish_mc.
    As soon as i start the scene[Ctrl+Enter] vanish_mc is VISUALLY removed. But the code still sees a collision somehow. How can i Entirely remove the object vanish_mc?
    Thank you for help and advice.

    Ah I think the problem is what my problem not which I proposed, my bad I was trying to keep it simple.
    the remove code in my problem actually looks like this:
    if(character_mc.hitTestObject(this["dollar_mc_"+String(i)])){
         removeChild(this["dollar_mc_"+String(i)]);
    I wanted it to be that way so I could add infinite "dollar_mc_" ' s without writing myself to death with code and or getting confused.
    Imagine it like a game where a character it picking up dollars, which would disappear once they intersect.
    And that exactly is what gives me that argument.
    Do you know a way i could write this code, or do you suggest to leave it that way...because it does run and work im just getting this argument while debugging.
    Thank you for all the help~

  • Batch removing objects from a PDF

    Hello, I have a PDF with an object appearing on every page of the document that I want to remove. I can select each object individually and remove them one by one, but that will take days (it's a 600 page document). Is there anyway to batch remove the objects?
    Thanks,
    Kyle

    I would go back to the program that created the PDF and delete the object there. If the object is an image, you could also try this: Advanced> Print production> Preflight> create PDF layers> Create separate layers for vector objects, text & images> Analyze and fix. Save and re-open your PDF.
    Go to View> navigation panels> layers. You should be able to turn the desired layer off.

Maybe you are looking for

  • Install files

    I want to save installation files like combo, etc. around our business ( 9  towns ) I don't want to download them every time I need to update near 47 macs !! I wish to save them to a hardrive, and run all installer at same time ...

  • Standby database SWITCHOVER_STATUS field is always NOT ALLOWED

    standby database: SQL> select switchover_status from v$database; SWITCHOVER_STATUS NOT ALLOWED select db_unique_name,database_role,open_mode,log_mode,protection_mode from v$database; DB_UNIQUE_NAME          DATABASE_ROLE     OPEN_MODE LOG_MODE     PR

  • Flash player for Device central

    Every time i try to preview a page in device central i get a message saying i need a flash player plugin. I click on ok and it takes me to adobe site that has download links for flash player 9. I have downloaded it 3 times now and i keep getting the

  • Connect Performance - Very Slow

    I have just installed Oracle pi 9.0.1) Release 1 on two machines running Windows 2000. The machines are in a local area network of 3 machines through an ADSL firewall router. When an application I have connects to oracle using <database user>@<databa

  • HT4623 I have a white square in the middle of my apps screen, and I am unable to search for new apps.

    I am unable to search for new apps because I have a blank white square in the middle of the Apps screen.