Answer the question
In order to leave comments, you need to log in
How to compare two ArrayList?
I have two ArrayList lists which are filled automatically by reading data from name.txt and name1.txt files using BufferedReader. the two lists can be of different lengths. I compared them like this:
String str ="";
List result1 = new ArrayList(list);
result1.removeAll(array);
str += ("New: " + result1);
and this code works. Question: is there another way to do this so that I can display the entire list and the elements that are not in the array were either in a different color or font, just somehow highlight them
Answer the question
In order to leave comments, you need to log in
There is. Stack the elements of array into a HashMap (store the number of each element there).
Then go through the list and, if there is a current element in the HashMap with a non-zero counter, display it in a different color and decrement the counter.
How to display in color depends on the language and platform. You can at least use the symbols "*" *** to highlight *** in the output.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question