Is it possible to add two separate arrays into one hash set?
PDB1982
0
Posting Whiz in Training
Recommended Answers
Jump to PostYes. The HashMap class's add() method takes an Object as a parameter. As you can see in the Java language specification, arrays are Objects.
See:
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashSet.html
Jump to PostAre you wanting to add the two arrays as two elements, or are you wanting to add all the elements in the arrays?
For the first caseint[] a = {1,2,3}; int[] b = {4,5}; HashSet h = new HashSet(); h.add(a); h.add(b); for (Object o : h) …
All 6 Replies
BestJewSinceJC
700
Posting Maven
PDB1982
0
Posting Whiz in Training
PDB1982
0
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
PDB1982
0
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.