Hey Folks!
Good Day...
Yesterday we saw little bit about Collections framework and what are the difficulties we faced without it . Today I learned List and Sets that is the nothing sub Interfaces of Main Interface.
Also Earlier in my Blog we saw the hierachy or classification of the collection Interface .
Collections are nothing but a collection of Objects
Firstly lets take a Set : A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction
This is the official definition from java team . It allows no duplicate and maintains no Insertion order.
Example : If we go to purchase a dress can we buy the dress already we have ? Nope
We maintain the order that shopkeeper packs in the bag ? Nope that's it.
Next one is fully inversed to this called List:
An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
Example : If we go the grocery shop can we buy same soap two times ? Ofcourse.
ArrayList al = new ArrayList();
al.add(10);
al.add(15);
When we giving the input 10 it is considered as a object not primitive datatype int.
Because of inbuilt wrapperclass it Boxes the Primitive datatype to Object. So every Datatype have wrapper class like for int it is Integer , for short it is Short , for double it is Double etc...
In the mid of the class Trained assigned some tasks to practice
Without using Arraylist you must add a element in the last and also wherever in the mid of the array
I tried both :
Also using Arraylist the task is create and store a student details :
Output :
Let's see tomorrow with new learnings and continue this topic in the next Blog...



Top comments (0)