您不妨研究这一条款,以便了解更多信息:
http://download-llnw.oracle.com/javase/tutorial/collections/interfaces/set.html
正如有人提到的那样,remove All(>
>是为此而制定的,但你将两次这样做,以便你能够编制一份双方都不存在的所有清单,然后,你可以把这两个结果结合起来,列出所有分歧。
但这是一种破坏性行动,因此,如果你不想失去信息,就复制<代码>。 Set ,按此操作。
<><>UPDATE:
看来,我对阵列中的假设是错误的,因此,<代码>remove All(>赢得了t work,但根据5点要求,将搜索的物品数量降为问题。
因此,它似乎有<代码>HashMap<String, Hor>是最佳选择,因为它正在快速搜索。
动物是至少一种财产的接口,String name
。 执行<代码>Animal的每个类别:<代码>Equals和hashCode
的代码。 可在以下网址查阅一些讨论:。 http://www.ibm.com/developerworks/java/library/j-jtp05273.html。 这样,如果你想把动物种类和名称结合起来,那就会被罚款。
So, the basic algorithm is to keep everything in the hashmaps, and then to search for differences, just get an array of keys, and search through to see if that key is contained in the other list, and if it isn t put it into a List<Object>
, storing the value there.
You will want to do this twice, so, if you have at least a dual-core processor, you may get some benefit out of having both searches being done in separate threads, but then you will want to use one of the concurrent datatypes added in JDK5 so that you don t have to worry about synchronizations in the combined list of differences.
So, I would write it first as a single-thread and test, to get some ideas as to how much faster it is, also comparing it to the original implmemntation.
Then, if you need it faster, try using threads, again, compare to see if there is a speed increase.
在进行优化之前,确保你对你已经拥有的一些衡量标准,以便你能够比较和看看一次变化是否会加快速度。
如果你在某个时候做了太多的改动,那么速度就会大大提高,但其他变化可能会导致业绩下降,因此,现在就会出现这种情况。
如果通过使用单位检测和检测,也许每100次,你就可以了解每个变化给你带来的改进。