What is data Structure?
Data structure is a way of organizing and manipulating data.In this article we are going to discuss different data structures that java has to offer.
what are Arrays?
arrays it is a list of cells that defines the size. So when you define the size the size is fixed, example if you have an array of six element and the size is six ,the index for the array, the index starts with zero.Arrays are really fast for data retrieval basically you can define data structure or the array itself. If you want to access a particular element you basically need to know where it is in the memory and don’t have to do any computation, so to retrieve an element from an array is just an O of N ,so it is really fast. Compact for the memory usage if the size is known.
Delete operation through it is a little bit hard because if you want to delete an element you have to make sure you reshuffle everything so that you can leave the array with some extra space.
There isn’t a delete method in an array,it is something you need to implement it yourself .Arrays are the building blocks to 2D array
2D arrays are a bunch of cells that are dimensions on the Y And X axis, it goes up and down. Anytime you want to have agreed basically use 2d array
Let’s look at list interface iterable interface, the collection interface in collection interface we have got various different implementation
The difference between the collection interface and list interface is that the collection interface has details that we can add stuff into. It is basically a collection of elements.
The list interface itself has away more information on how to perform certain operation with collection or list interface if you want to delete a particular index or retrieve at a particular index then the list has that functionality which any concrete class that implement the list interface know what to do .if you’ve got the implementation like red list, stack, vectors .all this differ the way you access the element.
The list interface allows duplication, it is not fixed in size like arrays, it is very fast for data retrieval
Stack data structure represents a last in first out stack of objects. It extends the vector with five operations that allows a vector to be treated as a stack so you have a push method. Which allow to push an element into stack,we have got pop which removes the element at the top the stack, peek method which allows you to see at very top the stack without removing it.
Pop actually removes it where else peek it just gives the value inside.
The difference between the vector and array list vector is synchronized,its thread safe implementation is not recommended to use array list.
The stack it follows the last thing first out, whereas with a que it follows first in first out, its a collection designed for holding elements prior for processing with queue, is an interface and we have various different implementations, the most popular is linked list.
Linked list is one implementation of the queue interface .Linked list is made up of multiple nodes in a nutshell where you have got the head node, each node contains reference to the next node and reference to the previous node.
There are two types of linked lists. this is where you have got the reference to the next and previous.
- Linked list is bi_directional.
Linked lists are very expensive in memory. You need to know the reference to the next and previous .
They have extra memory
The data structure is a set that contains no duplicate in the list interface, we saw you can have duplicates but with sets, no duplicates are allowed .
The set does not guarantee order.
Set contains no pair of element E1, such that E1 equals E2 altmost one null element as implied by its name,this interface models are mathematically set obstruction.
Map, its a collection of key value pairs.
The key cannot be duplicated and each key can map to one value
The most different key, you can also delete from the map.
Map.put passes the key
Hash function produces something known as hash code,hash code means mapping to its integer value
You can call the hash function on the same object and it will always produce the same hash code
Lists and maps are the ones that you are going to use most of the time