8:51 pm - Monday June 26, 2017

PriorityQueue example program to Remove a number/String from list

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Program is used to Remove a number/String from list using remove() method.

Example Program


import java.util.PriorityQueue;

public class PriorityQ {

public static void main(String[] args) {

PriorityQueue PQ = new PriorityQueue();

PQ.add(100);

PQ.add(12);

PQ.add(56);

PQ.add(89);

PQ.add(103);

System.out.println("The default way:");

for (Integer number : PQ) {

System.out.println(number);

}

PQ.remove(89);

System.out.println("The removing way:");

for (Integer number : PQ) {

System.out.println(number);

}

}
}

Output

    The default way:

     12

     89

     56

     100

     103

    The Removing way:

     12

     56

     103       /* 89 is removed from the list */

     100

 

Description:

Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element e such that o.equals(e), if this queue contains one or more such elements. Returns true if and only if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).

Specified by:

remove in interface Collection<E>

Overrides:

remove in class AbstractCollection<E>

Parameters:

o – element to be removed from this queue, if present

Returns:

true if this queue changed as a result of the call.

 

BACK

 

 

 

 

 

 

 

Filed in: Java Examples

Comments are closed.