Posts

Showing posts with the label Data sructures

Serialization Using java

Image
  In computing, serialization is the process of translating data structures or object state into a format that can be stored or transmitted and reconstructed later is called as serialization. Simply,Java is  an object oriented programming language.Machines store files as byte stream in any file in digital world.Java have many object which include data , & it can convert to the byte stream & write to file.After write as byte  stream(Called Serialization ), we can  send or store that data any where. If you can convert that byte stream successfully as same as to the  the previous object it called as the De-Serialization .     Importance of Serialization Communication: If you have two machines that are running the same code, and they need to communicate, an easy way is for one machine to build an object with information that it would like to transmit, Persistence: If you want to store the state of a particular operation in a database, it can be easily serialized to a byte array, an

Set Interface using Java

Image
Duplicate values cannot be stored in this data structure. 1)Hash Set: Stored values in random Manner without duplication.      Set<Integer> mySet=new HashSet<>();         mySet.add(10);         mySet.add(20);         mySet.add(30);         mySet.add(10);         System.out.println(mySet.size());//out 3         System.out.println(mySet);//out  [20, 10, 30]           System.out.println(mySet.contains(50));//out false Thre are 2 method to retrieve data from Hash set            //1.using  iterator           Iterator<Integer> iterator = mySet.iterator();          while(iterator.hasNext()){             System.out.println(iterator.next());            }          //2.using for each           for (Integer a:mySet) {             System.out.println(a);         }          //String           Set<String> mySet=new HashSet<>();         mySet.add("Jhone");         mySet.add("Ali");         mySet.add("Lisa");         mySet.add("Jhone"

Map Interface using Java

Image
Represents a mapping between a key and a value. Eg:-Key          Value          😜          "Jhone"          😁              "Ann"          😜               "Leo" If you  want to get any Value you must know key regards to value. There are 3 types of  maps in Map interface in java,          1.HashMap-Store data random manner,Minimum time  time complexity.Speed map compare to the          other MAPs.  import java.util.HashMap; import java.util.Map;     public static void main(String[] args) { Map<Integer,String> myMap=new HashMap<>();//create Map type HashMap object         myMap.put(10,"Jhone");//key,value         myMap.put(20,"Smith");         myMap.put(30,"Ana");         //Key stored & show in random manner         System.out.println(myMap);         //Jhone         System.out.println(myMap.get(10));         myMap.put(10,"Lisa");         //Lisa         System.out.println(myMap.get(10)); //Replace la