Java的:arraylist.contains&放大器;删除不工作 [英] java: arraylist.contains & remove not working

查看:134
本文介绍了Java的:arraylist.contains&放大器;删除不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中,其中包含对象的ArrayList,这些对象是由一个字符串名称和数量。

I have an ArrayList in Java, which contains Objects, these Objects are made of a string name and a number.

我要检查是否有任何对象是在两次列表,然后更新其中的一个数,然后删除另外一个,所以它不会得到算作另一次。

I want to check if any of the Objects is twice in the list and then update the number of one of them, afterwards delete the other one, so it wont get counted another time.

我已经知道它是如何工作的,但我有一个很大的问题,这两个methodes,包含和删除不跟我要处理的对象。
对于expamle我想删除它包含的名字XXXX的第一个对象,它不会删除的东西都没有。
这似乎是这两种方法都不能为自制的对象所做的。

I already know how it works, but i have a big problem, both methodes, "contains" and "remove" do not work with the objects i want to work with. For expamle i want to remove the first object which contains the name XXXX, it wont remove the thing at all. It seems like these two methods are not made for selfmade Objects.

有覆盖删除的方法和contains方法?
Eclipse不利于在这里与自动生成的东西。

Is there a way of overriding the remove and contains method ? Eclipse does not help here with the autogenerated stuff.

BTW:我有一个defiened自己等于在我的名单这是工作没有任何问题的对象方法(我一直以为ArrayList的方法会利用的对象方法)。

btw: i have defiened an own "equals" method for the objects in my list which is working without any problems ( i always thought the arraylist methods would make use of the object methods )..

感谢。

推荐答案

等于()散code()方法应该总是一前一后提供。

equals() and hashCode() methods should always be provided in tandem.

。看看重写equals和Java中的散列code

这篇关于Java的:arraylist.contains&放大器;删除不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆