Posts

HashMap

  //in hashmap duplicate value can we insert but , duplicate key not , all are unique. import java . util . HashMap ;   public class Basic {     public static void main ( String [] args ) {     HashMap < Integer , String > map = new HashMap <>();     map . put ( 78 , "ved" );     map . put ( 99 , "sneha" );     map . put ( 89 , "tarun" );     map . put ( 90 , "rajan" );     System . out . println ( map );     // size of map     System . out . println ( map . size ());     //  get(key)- gives the value of key     System . out . println ( map . get ( 90 ));     // remove(key) - it delete key and pair both     map . remove ( 89 );     System . out . println ( map );     // check value is exist or not     System . out . println ( map . containsValue ( "sneha" ));     // check key is exist...

HashSet

  import java . util . HashSet ; // HashSet is an interface in java. // if we want to remove  an element which is not exist in set then we do not get any error. // in set there is no concept of index , so we use for each loop. // if any element is already present , then we can not add again , no error. public class Basic {     public static void main ( String [] args ) {         HashSet < Integer > set = new HashSet <>();         // Insert O(1)         set . add ( 89 );         set . add ( 10 );         set . add ( - 987 );         set . add ( 100 );         // size O(1)         System . out . println ( set . size ());         //in set elements are stroe randomly         System . out . println ( set );         // remove element O(...

python.

No, you cannot use the dollar sign ( $ ) in a Python variable name.   we can use 3 way to print string - ',",'''. single ,double, triple quotes.

linked list new version.

  class Sll { // user defined data structure     Node head ;     Node tail ;     int size ; void size (){     System . out . println ( "length of list is=" + size ); } void deleteAtIndex ( int ix ){ if ( ix < 0 || ix >= size ) throw new IndexOutOfBoundsException ( "invalid index" ); if ( ix == 0 ){   deleteAtStart ();   return ; } if ( ix == size - 1 ){     deleteAtEnd ();     return ; } Node x = head ; for ( int i = 0 ; i < ix - 1 ; i ++ ){     x = x . next ; } x . next = x . next . next ; size -- ;   } void deleteAtEnd (){ if ( head == null )     throw new IllegalStateException ( "list is already empty" );     if ( head == tail ){         head = tail = null ;         size -- ;         return ;     }     Node x = head ;     while ( x . next != tail ){   ...

linkedlist

class SLL {     private Node head ;     private Node tail ;     private int size ;     void deleteAtIndex ( int ix ){     if ( ix < 0 || ix >= size ){     throw new IndexOutOfBoundsException ( "bhai wrong index mat dal" );     }     if ( ix == 0 ){         deleteAtStart ();         return ;     }     if ( ix == size - 1 ){         deleteAtEnd ();         return ;     }     Node x = head ;     for ( int i = 0 ; i < ix - 1 ; i ++ ){         x = x . next ;     }       x . next = x . next . next ;       size -- ;     }     void deleteAtEnd (){         if ( tail == null ){             System . out . println ( "list is already empty" ...

interface

 interface ICalculator{ // public and abstract void add(int a, int b); void sub(int a, int b); void mul(int a, int b); void div(int a, int b); } class Cal implements ICalculator{   public void add(int a , int b){       System.out.println("the sum is="+(a+b));   }   public void sub(int a , int b){       System.out.println("the subtraction is="+(a-b));   }   public void mul(int a , int b){       System.out.println("the multiplication is="+(a*b));   }   public void div(int a , int b){       System.out.println("the division is="+(a/b));   } } public class Main { public static void main(String[] args) { ICalculator c = new Cal(); c.add(10,20); c.sub(4,2); c.mul(2,8);     c.div(9,3); } } ------------------------------------------------------------------------------------------------------------------ interface ICalculator1{ // public and abstract void add(int a,...

oops.

Inheritance--- --------------------------- class person{     public int age;     public String name;     public String address; } class Student extends person{     public int marks;     public String grade;     Student(int age , String name , String address , int marks , String grade){         this.age=age;         this.name=name;         this.address=address;         this.marks=marks;         this.grade=grade;     }     public void disp(){         System.out.println("age is ="+age);         System.out.println("name is ="+name);         System.out.println("address is ="+address);         System.out.println("marks is ="+marks);         System.out.println("grade is ="+grade);     } } public class Main { ...