Priority Queue : In Java Priority Queue is a queue which keeps its elements sorted as per their natural order( example in ascending orders for Integer, alphabetical a-z for alphabets) or using a custom Comparator at the time of creation you can custom sort it. It has most method similar to a queue add, clear, poll, peek As priority queue have to compare elements to keep in order so elements must be comparable otherwise, it will throw ClassCastException . As null can not be compared so you are not allowed to insert null too A program to sort priority queue using Lambda function in Java c lass PriorityQueueLambdaJava { public List<Integer> KFrequent( int [] nums, int k) { Map<Integer, Integer> map = new HashMap<>(); for ( int j: nums) { map .put(j, map .getOrDefault(j, 0 ) + 1 ); } PriorityQueue<Map.Entry<Integ...
Java InputOutput : Most of the application needs to process some input and then produce output to a network file or local file etc. There is a java package java.io which provides input and output through data streams , serialization and the file system.
The package covers most of the input and output operations required but not the GUI I/O operations which are covered in Swing, JSP etc in Java enterprise.
this package is primarily focused on input and output to files, network streams, internal memory buffers etc. However, the Java IO package does not contain classes to open network sockets which are necessary for network communication. For opening network sockets there is another networking package in java.
Typical Java IO sources : FILE, Network IO, Streams Streams : Conceptually, a stream is a endless flow of data from where you can either read or write . Streams in Java IO can be either byte based (reading and writing bytes) or character based (reading and wri...