Results 1 to 5 of 5
Thread: HashSet with array
- 03-10-2011, 10:49 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 19
- Rep Power
- 0
HashSet with array
Hello ALL
I have got 2 method:
1st - Returns Set <Integer> which contains an array
2nd - Takes returned value from 1st method as HashSet argument.
Then I need to find consecutive numbers like 1,2 in order to find the numbers I need to first loop through the HashSet, but there is no length, so how do I do it ??
Cheers in advance for all your support
pi4r0nLast edited by pi4r0n; 03-10-2011 at 10:52 PM.
-
This confuses me. How can a Set<Integer> contain an array?
HashSet has a size() method. It also implements the Iterable interface and you can iterate through it with this or the foreach loop.Then I need to find consecutive numbers like 1,2 in order to find the numbers I need to first loop through the HashSet, but there is no length, so how do I do it ??
- 03-10-2011, 11:03 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 18
- Rep Power
- 0
See: HashSet (Java Platform SE 6)
Is this what you are trying to do?
Java Code:Set<Integer> set = hashSet.keySet(); Iterator<Integer> setIt = hashSet.iterator(); while(setIt.hasNext()) { int num = setIt.next() <Do stuff> }
- 03-10-2011, 11:18 PM #4
Another problem: HashSet makes no guarantee of the order of the components. If you are looking to see if values are in order then a HashSet is the wrong choice. TreeSet or extracting values into another Collection and then sorting them would be better.
- 03-10-2011, 11:20 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 19
- Rep Power
- 0
I just found a post on this forum that might relates to what I am trying to do.
I'll take it as a example and will see how it goes
Similar Threads
-
Getting value for key in HashSet
By Venny in forum New To JavaReplies: 12Last Post: 02-02-2011, 08:42 AM -
Adding to a HashSet
By Neivaed in forum New To JavaReplies: 6Last Post: 12-05-2010, 06:16 PM -
:( anyone here plz help on HashSet
By waklo99 in forum New To JavaReplies: 8Last Post: 09-20-2010, 03:02 AM -
HashSet anomaly
By jon80 in forum New To JavaReplies: 1Last Post: 06-21-2009, 08:22 PM -
Iterating through a HashSet
By Java Tip in forum Java TipReplies: 0Last Post: 01-21-2008, 04:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks