Sets in java is a structure that gives an architecture to store and change the group of objects.
All the missions that you apply on a data such as searching, sorting, inserting, manipulation, deletion etc. can be pull off by Java Sets.
Java Set simply means a single unit of objects. Java Set structure gives a lot of borderlines (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PrecedenceQueue, HashSet, LinkedHashSet, TreeSet etc).
Contents
What is structure in java
- gives readymade
- represents set of classes and
- is
What is Set structure
Â
Set structure represents a unified architecture for storing and manipulating group of objects. It has:
- Borderlines and its ful filments e. classes
- Algorithm
Java ArrayList class
Java ArrayList class uses a dynamic array for storing the elements. It inherits ConceptualList class and applies List borderline.
The important points about Java ArrayList class are:
- Java ArrayList class can store(contain) duplicate
- Java ArrayList class maintains inserting
- Java ArrayList class is non
- Java ArrayList allows random entrance because array works at the index
- In Java ArrayList class, manipulation is slow because a lot of shifting needs to be happenred if any element is removed from the array
ArrayList class announcement
Â
Let’s see the announcement for java.util.ArrayList class.
Creaters of Java ArrayList
Â
Â
Â
Creater                                Description |
|
ArrayList() | It is used to design an empty array list. |
ArrayList(Set c) | It is used to design an array list that is established with the elements of the set c. |
ArrayList(int capacity) | It is used to design an array list that has the specified  initial capacity. |
Â
Java ArrayList Example import java.util.*;
class TestSet1{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();//Creating arraylist list.add(“Ravi”);//Adding object in arraylist
list.add(“ram”);
list.add(“syam”);
list.add(“ayushi”);
//Traversing list through Iterator Iterator itr=list.iterator(); while(itr.hasNext()){ System.out.println(itr.next()); } }}
ram syam ayushi
syam |
vector
Â
ArrayList and Vector both applies List borderline and maintains inserting order.
But there are a lot of differences between ArrayList and Vector classes that are given below.
ArrayList | Vector |
1) ArrayList is not defended. | Vector is defended. |
2)ArrayList additions 50% of current array size if number of element exceeds from its capacity. | Vector additions 100% means doubles the array size if total number of element exceeds than its capacity. |
3)ArrayList is not a legacy class, it is introduced in JDK 1.2. | Vector is a legacy class. |
4) ArrayList is fast because it is non-defended. |
Vector is slow because it is defended i.e. in alternating environment, it will hold the other alternates in runnable or non-runnable state until current alternate releases the lock of object. |
5) ArrayLis tuses Iterator borderline to traverse the elements. | Vector uses Iteration borderline to traverse the                                      elements. But it can use Iterator also. |
Example of Java Vector
Â
Let’s see a simple example of java Vector class that uses Iteration borderline.
- import util.*;
- class TestVector1{
- public static void main(String args[]){
- Vector<String> v=new Vector<String>();//creating vector
- add(“ram”);//way(method) of Set
- addElement(“vishnu”);//way(method) of Vector
- addElement(“pratap”);
- //traversing elements using Iteration
- Iteration e=v.elements();
- while(e.hasMoreElements()){
- out.println(e.nextElement()); 12. } } }
Output:
ram
vishnu pratap |
Â
Â
Java Disputable class
Â
Java Disputable class applies a disputable, which maps keys to values. It inherits Dictionary class and applies the Map borderline.
The important points about Java Disputable class are:
- A Disputable is an array of list. Each list is known as a bucket. The position of bucket is identified by calling the hashcode() way(method) . A Disputable insure values based on the
- It insure only unique
- It may have not have any null key or
- It is
Disputable class announcement
Â
Let’s see the announcement for java.util.Disputable class.
- public class Disputable<K,V> expand Dictionary<K,V> applies Map<K,V>, Cloneable, Ser ializable
Disputable class Parameters
Â
Let’s see the Parameters for java.util.Disputable class.
- K: It is the type of keys reconstructed by this
- V: It is the type of mapped
Creaters of Java Disputable class
Â
Creater |
Â
Description |
||
Disputable() | It is the default creater of hash table it instantiates the Disputable class. | ||
Disputable(int size) | It is used to accept an integer parameter and produces a hash table that has an initial size specified by integer value size. | ||
Â
Disputable(int fillRatio) |
size, | float | Â
It is used to produce a hash table that has an initial size specified by size and a fill ratio specified by fillRatio. |
Java Disputable Example
import java.util.*;
class TestSet16{
public static void main(String args[]){ Disputable<Integer,String> hm=new Disputable<Integer,String>(); hm.put(100,”vishnu”);
hm.put(102,”ram”);
hm.put(101,”ayushi”);
hm.put(103,”shyam”);
for(Map.Entry m:hm.entrySet()){ System.out.println(m.getKey()+” “+m.getValue());
} } }
Output:
103 vishnu
102 ram 101 ayushi 100 shyam |