Wednesday, 7 March 2018
How to find Min and Max value from stack
Its very simple.
1. Sort the value in stack using Collections.sort()
2.then find the min by using Collections.min()
3.find the max bu using Collections.max() method
package ListExample;
import java.util.Collections;
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack stack = new Stack();
stack.push(12);
stack.push(12);
stack.push(9);
stack.push(25);
stack.push(55);
stack.push(65);
System.out.println(stack);//printing without sorting
Collections.sort(stack);//Sorting the stack
System.out.println("Max number is "+Collections.max(stack));//Printing Max number in stack
System.out.println("Min number is "+Collections.min(stack));//Return Minimum number in stack
}
}
1. Sort the value in stack using Collections.sort()
2.then find the min by using Collections.min()
3.find the max bu using Collections.max() method
package ListExample;
import java.util.Collections;
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack stack = new Stack();
stack.push(12);
stack.push(12);
stack.push(9);
stack.push(25);
stack.push(55);
stack.push(65);
System.out.println(stack);//printing without sorting
Collections.sort(stack);//Sorting the stack
System.out.println("Max number is "+Collections.max(stack));//Printing Max number in stack
System.out.println("Min number is "+Collections.min(stack));//Return Minimum number in stack
}
}
Subscribe to:
Posts (Atom)
session-per-request in hibernate
The most common pattern in a multi-user client/server application is session-per-request . In this model, a request from the client is sent...
-
The most common pattern in a multi-user client/server application is session-per-request . In this model, a request from the client is sent...
-
you can call it as many times and anywhere you like once you get hold of your org.hibernate.SessionFactory. The getCurrentSession() method ...
-
Firstly why we need custom serialization ?. .look😁 we we serialized the object there may the chance of loosing some information due to ...