Code example for TreeSet

Methods: add, iterator

0
        hh2.setId(1L); 
        Household hh3 = new Household(); 
        hh3.setId(8L); 
        Household hh4 = new Household(); 
        hh4.setId(5L); 
        SortedSet<Household> hhs = new TreeSet<Household>(); 
        hhs.add(hh1); 
        hhs.add(hh2); 
        hhs.add(hh3); 
        hhs.add(hh4); 
 
        Iterator<Household> iterator = hhs.iterator(); 
        assertEquals(1L, iterator.next().getId().longValue()); 
        assertEquals(3L, iterator.next().getId().longValue()); 
        assertEquals(5L, iterator.next().getId().longValue()); 
        assertEquals(8L, iterator.next().getId().longValue()); 
    } 
 
}