PriorityQueue returning incorrect ordering for custom comparator?
I combine a priority level(from 0 to 3) with user ID and use a comparator to sort the priority queue.
The main function and comparator are as below

    public class PriQueTest {
	  public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Comparator<String> comparator = new StringPriComparator();
        PriorityQueue<String> queue = 
            new PriorityQueue<String>(3, comparator);
        queue.add("3"+"128763711");
        queue.add("2"+"128763712");
        queue.add("0"+"128763718");
        queue.add("1"+"128763713");
        queue.add("3"+"128763714");
        queue.add("2"+"128763715");
        queue.add("2"+"128763716");
        queue.add("3"+"128763717");
        
        while (queue.size() != 0)
        {
            System.out.println( (queue.remove().substring(1)));
        }
		
      }
	  public static class StringPriComparator implements Comparator<String>
	  {
	    @Override
	    public int compare(String x, String y)
	    {
	        if (Integer.parseInt(x.substring(0, 1)) >  Integer.parseInt(y.substring(0, 1)))
	        {
	            return -1;
	        }
	        if (Integer.parseInt(x.substring(0, 1)) <  Integer.parseInt(y.substring(0, 1)))
	        {
	            return 1;
	        }
	        return 0;
	        
	     }
	  }
	

    }

Sorting of priorities is correct but the sorting of users within the same priority level is not correct

The output of above code is 

    128763711
    128763714
    128763717
    128763716
    128763712
    128763715
    128763713
    128763718

where as the expected output is as follows

    128763711
    128763714
    128763717
    128763712*
    128763715*
    128763716*
    128763713
    128763718

Any ideas if something not correct or Is my comparator wrong?

Thanks

AurM

PriorityQueue returning incorrect ordering for custom comparator?
===

I combine a priority level(from 0 to 3) with user ID and use a comparator to sort the priority queue.
The main function and comparator are as below

    public class PriQueTest {
	  public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Comparator<String> comparator = new StringPriComparator();
        PriorityQueue<String> queue = 
            new PriorityQueue<String>(3, comparator);
        queue.add("3"+"128763711");
        queue.add("2"+"128763712");
        queue.add("0"+"128763718");
        queue.add("1"+"128763713");
        queue.add("3"+"128763714");
        queue.add("2"+"128763715");
        queue.add("2"+"128763716");
        queue.add("3"+"128763717");
        
        while (queue.size() != 0)
        {
            System.out.println( (queue.remove().substring(1)));
        }
		
      }
	  public static class StringPriComparator implements Comparator<String>
	  {
	    @Override
	    public int compare(String x, String y)
	    {
	        if (Integer.parseInt(x.substring(0, 1)) >  Integer.parseInt(y.substring(0, 1)))
	        {
	            return -1;
	        }
	        if (Integer.parseInt(x.substring(0, 1)) <  Integer.parseInt(y.substring(0, 1)))
	        {
	            return 1;
	        }
	        return 0;
	        
	     }
	  }
	

    }

Sorting of priorities is correct but the sorting of users within the same priority level is not correct

The output of above code is 

    128763711
    128763714
    128763717
    128763716
    128763712
    128763715
    128763713
    128763718

where as the expected output is as follows

    128763711
    128763714
    128763717
    128763712*
    128763715*
    128763716*
    128763713
    128763718

Any ideas if something not correct or Is my comparator wrong?

Thanks

AurM
