Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Arvore implements Comparable<Arvore>{
- int altura;
- public Arvore(int alt) {
- altura = alt;
- }
- @Override
- public String toString() {
- return altura + "";
- }
- @Override
- public int compareTo(Arvore a) {
- // TODO Auto-generated method stub
- return a.altura;
- }
- }
- import java.util.Iterator;
- import java.util.TreeSet;
- public class UsandoTreeSetComObjeto {
- public static void main(String[] args) {
- TreeSet<Arvore> arvore = new TreeSet<Arvore>();
- arvore.add(new Arvore(2));
- arvore.add(new Arvore(1));
- arvore.add(new Arvore(3));
- Iterator<Arvore> iterator = arvore.iterator();
- while(iterator.hasNext()) {
- System.out.println(iterator.next()+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement