What is the use of <> in Stack s = new Stack<>();?
What is the use of <>
<> are Generics, used for assigning data type to the stack or any other data structure.
Usually we see the format as Stack<Data_Type> stack= new Stack<>();
When we define a class in java we want that class to work for all the Data Types not only for one specified data type. So when you define a new class in java and you want that the class must work for all the data types then we use Generics, which will be predefined in the class. And so as when Java was developed it was kept in the mind that the inbuilt classes must work for all the data types not only for one so that if you want to make a stack of integer you can make it and using the same class but the different data type such as strings you can specify it in the angular brackets .
For Eg-
Stackstack=new Stack<>();