Auf Thema antworten

Einmal Test-Klasse:

[code=Java]import java.util.*;


public class Test implements Comparable<Test>{

        private int value;

      

        public Test(int value){

            this.value = value;

        }

      

        public int getValue(){

            return value;

        }


        @Override

        public int compareTo(Test o) {

            return Integer.compare(this.value, o.getValue());

        }

      

        @Override

        public String toString(){

            return ""+value;

        }

    }[/code]


Und die Main zum Testen:

[code=Java]import java.util.*;


public class Main{

   

    public static void main(String[] args){

      

        Test x = new Test(5);

        Test y = new Test(8);

        Test z = new Test(3);

      


        PriorityQueue <Test> queue = new PriorityQueue<>();

      

        queue.offer(x);

        queue.offer(y);

        queue.offer(z);

             


        System.out.println(queue);

    }

}

[/code]



Oben