Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Sorry If you are thinking that it is a repeated post. But the situation is different here. I have read several posts for it but not getting the exact thing I am looking for. I know How to develop a complex logic for this but please take a look this is for android and we can't expect too much processing on the device due to to limited resources available. I have an ArrayList of an bean class objects consisting five fields as Java Bean -- MyShares
I have another ArrayList of String which contains only filepaths. Now what I want is to remove all the common elements between the two arraylist means the file paths in seconds arraylist and file path in first arraylist objects are similar then I have to remove from both of the arraylist But I Don't want a new arraylist which contains the uncommon elemenst But I want to get my both arraylist only without their common elements. Please help me. | ||||
You could use a Assume we are given a list Steps:
Note that you need to be careful in steps 3 and 4, because you need to back up one of the collections.
Prints:
| ||||
Rough Java code:
This won't be | ||||
I will go with some clues for you Suppose you have two lists one for bean objects namely myBeans and another for filePaths namely filePaths
it is just a flow to make you clear for what to do; you can further customize it according to your needs. | |||
You can use an outer loop to scan over the Bean objects, and an inner loop to scan over the file paths. pseudo code:
I'm not sure if my extra arraylists to track the removed arraylists go against your question or not since the original arrays remain. If you presort both arrays on the path and keep track of the position in each area (not exhaustive search) you can improve it from n2 to nlgn | ||||
lang-java
.
stackoverflow.comm
No comments:
Post a Comment