Removing full object from a value The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?PHP: Delete an element from an arrayHow to get an enum value from a string value in Java?Checking if a key exists in a JavaScript object?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?

How should I connect my cat5 cable to connectors having an orange-green line?

Physiological effects of huge anime eyes

Arrows in tikz Markov chain diagram overlap

How exploitable/balanced is this homebrew spell: Spell Permanency?

Can Sri Krishna be called 'a person'?

How can I replace x-axis labels with pre-determined symbols?

What difference does it make matching a word with/without a trailing whitespace?

Arity of Primitive Recursive Functions

Creating a script with console commands

Man transported from Alternate World into ours by a Neutrino Detector

Is there a rule of thumb for determining the amount one should accept for a settlement offer?

Direct Implications Between USA and UK in Event of No-Deal Brexit

Find a path from s to t using as few red nodes as possible

Find the majority element, which appears more than half the time

Is a linearly independent set whose span is dense a Schauder basis?

Is it possible to make a 9x9 table fit within the default margins?

How do I secure a TV wall mount?

Prodigo = pro + ago?

Strange use of "whether ... than ..." in official text

Why doesn't Shulchan Aruch include the laws of destroying fruit trees?

pgfplots: How to draw a tangent graph below two others?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

Free fall ellipse or parabola?

How can I prove that a state of equilibrium is unstable?



Removing full object from a value



The Next CEO of Stack OverflowIs Java “pass-by-reference” or “pass-by-value”?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?PHP: Delete an element from an arrayHow to get an enum value from a string value in Java?Checking if a key exists in a JavaScript object?How do I determine whether an array contains a particular value in Java?Sort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?










0















Helper Class



public class HomeScreenChatsHelper implements Comparable 

private String ID;
private String Name;
private String Image;
private String From;
private String Seen;
private String LastMessage;
private String LastMessageTime;

public HomeScreenChatsHelper()



public HomeScreenChatsHelper(String id, String name, String image, String from, String seen, String lastmessage, String lastMessageTime)
this.ID=id;
this.Name = name;
this.Image = image;
this.From = from;
this.Seen = seen;
this.LastMessage = lastmessage;
this.LastMessageTime = lastMessageTime;


public String getID()
return ID;


public void setID(String id)
ID = id;


public String getName()
return Name;


public void setName(String name)
Name = name;


public String getImage()
return Image;


public void setImage(String image)
Image = image;


public String getMessage()
return LastMessage;


public void setMessage(String message)
LastMessage = message;


public String getTime()
return LastMessageTime;


public void setTime(String time)
LastMessageTime = time;


public String getFrom()
return From;


public void setFrom(String from)
From = from;


public String getSeen()
return Seen;


public void setSeen(String seen)
Seen = seen;


@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public int compareTo(Object comparestu)
long compareage= Long.parseLong(((HomeScreenChatsHelper)comparestu).getTime());

long a = Long.parseLong(LastMessageTime);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)


return Long.compare(a,compareage);


@Override
public boolean equals(Object o)
if (this == o) return true;
if (!(o instanceof HomeScreenChatsHelper)) return false;

HomeScreenChatsHelper that = (HomeScreenChatsHelper) o;

return getID().equals(that.getID());


@Override
public int hashCode()
return getID().hashCode();



Activity



 for(HomeScreenChatsHelper str : mChats) 
if (str.getID().equals(ID))
mChats.remove(ID);
break;




There are a ton of tutorials on how to do it and I've spent the past week looking for a solution and I still don't have it. Is there anyway I can remove an whole object by just specifying just the ID? I wont have the values of all the other fields so I just want to remove a particular object by its ID. Also I cant use the clear option because I need the other data. So can someone help me out please?



With the present code nothing happens. No errors but doesn't work










share




share|improve this answer





























    0














    By using java-8 you can filter the list, result will be the List<HomeScreenChatsHelper> that does have HomeScreenChatsHelper with same id



    List<HomeScreenChatsHelper> mChats = new ArrayList<>();

    //filter
    List<HomeScreenChatsHelper> result = mChats.stream()
    .filter(str->!str.getId().equals(Id)).
    .collect(Collectors.toList());


    Or by using Iterator



    // Iterator.remove() 
    Iterator itr = mChats.iterator();
    while (itr.hasNext())

    HomeScreenChatsHelper x = itr.next();
    if (x.getId().equals(Id))
    itr.remove();
    }
    }





    share|improve this answer



























      0












      0








      0







      By using java-8 you can filter the list, result will be the List<HomeScreenChatsHelper> that does have HomeScreenChatsHelper with same id



      List<HomeScreenChatsHelper> mChats = new ArrayList<>();

      //filter
      List<HomeScreenChatsHelper> result = mChats.stream()
      .filter(str->!str.getId().equals(Id)).
      .collect(Collectors.toList());


      Or by using Iterator



      // Iterator.remove() 
      Iterator itr = mChats.iterator();
      while (itr.hasNext())

      HomeScreenChatsHelper x = itr.next();
      if (x.getId().equals(Id))
      itr.remove();
      }
      }





      share|improve this answer















      By using java-8 you can filter the list, result will be the List<HomeScreenChatsHelper> that does have HomeScreenChatsHelper with same id



      List<HomeScreenChatsHelper> mChats = new ArrayList<>();

      //filter
      List<HomeScreenChatsHelper> result = mChats.stream()
      .filter(str->!str.getId().equals(Id)).
      .collect(Collectors.toList());


      Or by using Iterator



      // Iterator.remove() 
      Iterator itr = mChats.iterator();
      while (itr.hasNext())

      HomeScreenChatsHelper x = itr.next();
      if (x.getId().equals(Id))
      itr.remove();
      }
      }






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 7 at 20:01

























      answered Mar 7 at 19:47









      DeadpoolDeadpool

      7,7572831




      7,7572831























          0














          Your question is quite unclear. is mChats a List containing HomeScreenChatsHelper objects?
          I assume so. If this is the case, then you can change your foreach loop into the normal loop



          //Assuming mChats is List e.g ArrayList
          for (int i = 0; mChats.size(); i++)
          if (mChats.get(i).getID().equals(ID))
          mChats.remove(i);
          break;







          share|improve this answer























          • java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

            – user11164956
            Mar 8 at 6:33















          0














          Your question is quite unclear. is mChats a List containing HomeScreenChatsHelper objects?
          I assume so. If this is the case, then you can change your foreach loop into the normal loop



          //Assuming mChats is List e.g ArrayList
          for (int i = 0; mChats.size(); i++)
          if (mChats.get(i).getID().equals(ID))
          mChats.remove(i);
          break;







          share|improve this answer























          • java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

            – user11164956
            Mar 8 at 6:33













          0












          0








          0







          Your question is quite unclear. is mChats a List containing HomeScreenChatsHelper objects?
          I assume so. If this is the case, then you can change your foreach loop into the normal loop



          //Assuming mChats is List e.g ArrayList
          for (int i = 0; mChats.size(); i++)
          if (mChats.get(i).getID().equals(ID))
          mChats.remove(i);
          break;







          share|improve this answer













          Your question is quite unclear. is mChats a List containing HomeScreenChatsHelper objects?
          I assume so. If this is the case, then you can change your foreach loop into the normal loop



          //Assuming mChats is List e.g ArrayList
          for (int i = 0; mChats.size(); i++)
          if (mChats.get(i).getID().equals(ID))
          mChats.remove(i);
          break;








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 19:52









          Ezekiel SebastineEzekiel Sebastine

          14617




          14617












          • java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

            – user11164956
            Mar 8 at 6:33

















          • java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

            – user11164956
            Mar 8 at 6:33
















          java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

          – user11164956
          Mar 8 at 6:33





          java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 On the 2nd Line

          – user11164956
          Mar 8 at 6:33











          0














          The easiest way in Java 8 or later is with Collection#removeIf:



          mChats.removeIf(str -> str.getID().equals(ID));


          By the way, the convention in Java is for fields to begin with a lowercase letter.






          share|improve this answer



























            0














            The easiest way in Java 8 or later is with Collection#removeIf:



            mChats.removeIf(str -> str.getID().equals(ID));


            By the way, the convention in Java is for fields to begin with a lowercase letter.






            share|improve this answer

























              0












              0








              0







              The easiest way in Java 8 or later is with Collection#removeIf:



              mChats.removeIf(str -> str.getID().equals(ID));


              By the way, the convention in Java is for fields to begin with a lowercase letter.






              share|improve this answer













              The easiest way in Java 8 or later is with Collection#removeIf:



              mChats.removeIf(str -> str.getID().equals(ID));


              By the way, the convention in Java is for fields to begin with a lowercase letter.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 7 at 20:30









              David ConradDavid Conrad

              10.1k13039




              10.1k13039



























                  draft saved

                  draft discarded
















































                  Thanks for contributing an answer to Stack Overflow!


                  • Please be sure to answer the question. Provide details and share your research!

                  But avoid


                  • Asking for help, clarification, or responding to other answers.

                  • Making statements based on opinion; back them up with references or personal experience.

                  To learn more, see our tips on writing great answers.




                  draft saved


                  draft discarded














                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55051652%2fremoving-full-object-from-a-value%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown





















































                  Required, but never shown














                  Required, but never shown












                  Required, but never shown







                  Required, but never shown

































                  Required, but never shown














                  Required, but never shown












                  Required, but never shown







                  Required, but never shown







                  Popular posts from this blog

                  Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                  Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                  Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved