public String toString(int maxKeysToPrint,boolean multiline){
  PriorityQueue<E> pq=clone();
  StringBuilder sb=new StringBuilder(multiline ? "" : "[");
  int numKeysPrinted=0;
  NumberFormat f=NumberFormat.getInstance();
  f.setMaximumFractionDigits(5);
  while (numKeysPrinted < maxKeysToPrint && pq.hasNext()) {
    double priority=pq.getPriority();
    E element=pq.next();
    sb.append(element == null ? "null" : element.toString());
    sb.append(" : ");
    sb.append(f.format(priority));
    if (numKeysPrinted < size() - 1)     sb.append(multiline ? "\n" : ", ");
    numKeysPrinted++;
  }
  if (numKeysPrinted < size())   sb.append("...");
  if (!multiline)   sb.append("]");
  return sb.toString();
}

public String toString ( int maxKeysToPrint , boolean multiline ) { PriorityQueue < E > pq = clone ( ) ; StringBuilder sb = new StringBuilder ( multiline ? "" : "[" ) ; int numKeysPrinted = 0 ; NumberFormat f = NumberFormat . getInstance ( ) ; f . setMaximumFractionDigits ( 5 ) ; while ( numKeysPrinted < maxKeysToPrint && pq . hasNext ( ) ) { double priority = pq . getPriority ( ) ; E element = pq . next ( ) ; sb . append ( element == null ? "null" : element . toString ( ) ) ; sb . append ( " : " ) ; sb . append ( f . format ( priority ) ) ; if ( numKeysPrinted < size ( ) - 1 ) sb . append ( multiline ? "\n" : ", " ) ; numKeysPrinted ++ ; } if ( numKeysPrinted < size ( ) ) sb . append ( "..." ) ; if ( ! multiline ) sb . append ( "]" ) ; return sb . toString ( ) ; }
returns a representation of the queue in decreasing priority order , displaying at most maxkeystoprint elements and optionally printing one element per line .
