I have to sets of strings
set 1:
"hello"
"world"
"stackoverflow"
set 2:
"world"
"hello"
"stackoverflow"
Before I tried to compare the content, I know exactly that these two sets contain only unique values. So I am not thinking about java Set
for unique test.
So in Java, what should be the cheapest way to compare these two sets? By cheapest, I mean memory like.
I know I can do ArrayList.contains()
forLoop, is there a better way?
And I was told Java HashSet
consumes 5 times more resources than ArrayList
when containing same length of contents. Is that true?
UPDATE
I don't have sample for you, since this is just an idea came to my mind.
By two sets of strings, I meant literally set, this set can also be stored in Java ArrayList
.
is to compare these two sets of string to know if they are containing the same contents. of course I know before the actions that they both containing unique contents.
UPDATESorry, this is not a practical problem I ran across with. This is just an idea I am wondering about.