I have to compare a master array with a child array and tag the master array with a certain text (say “#”) for the common ones –
MasterArray = {"A", "B", "C", "D", "E"}
ChildArray = {"A", "C"}
OutputArray = {"A#", "B", "C#", "D", "E"}
The output will be displayed directly to JList. I am using it here to explain the requirement.
What should I use to get the same output…?
Convert your arrays to ArrayLists using
Arrays.asListto make them easier to work with. Then iterate over your master array and check if the child array contains each element using theArrayList.containsmethod. If it does, append ‘#’ to the element. Here is some sample code to help you: