<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: NANDYALA ANUROOP</title>
    <description>The latest articles on DEV Community by NANDYALA ANUROOP (@anuroop123).</description>
    <link>https://dev.to/anuroop123</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F629262%2F24e60f77-d21d-4d58-827a-5ad3c16d3256.png</url>
      <title>DEV Community: NANDYALA ANUROOP</title>
      <link>https://dev.to/anuroop123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anuroop123"/>
    <language>en</language>
    <item>
      <title>#Hashing in Java</title>
      <dc:creator>NANDYALA ANUROOP</dc:creator>
      <pubDate>Thu, 25 Nov 2021 12:58:07 +0000</pubDate>
      <link>https://dev.to/anuroop123/hashing-in-java-53e8</link>
      <guid>https://dev.to/anuroop123/hashing-in-java-53e8</guid>
      <description>&lt;h1&gt;
  
  
  Hashing
&lt;/h1&gt;

&lt;p&gt;*In hashing there is a hash function that maps keys to some values. But these hashing function may lead to collision that is two or more keys are mapped to same value. Chain hashing avoids collision. The idea is to make each cell of hash table point to a linked list of records that have same hash function value.&lt;br&gt;
Let’s create a hash function, such that our hash table has ‘N’ number of buckets. &lt;br&gt;
To insert a node into the hash table, we need to find the hash index for the given key. And it could be calculated using the hash function. &lt;br&gt;
Example: hashIndex = key % noOfBuckets&lt;br&gt;
Insert: Move to the bucket corresponds to the above calculated hash index and insert the new node at the end of the list.&lt;br&gt;
Delete: To delete a node from hash table, calculate the hash index for the key, move to the bucket corresponds to the calculated hash index, search the list in the current bucket to find and remove the node with the given key (if found). *&lt;/p&gt;

&lt;h1&gt;
  
  
  Methods to implement Hashing in Java
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Method-1:
&lt;/h2&gt;

&lt;p&gt;with help of HashTable (A synchronized implementation of hashing)&lt;br&gt;
import java.util.*;&lt;br&gt;
class GFG {&lt;br&gt;
    public static void main(String args[])&lt;br&gt;
    {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Create a HashTable to store
    // String values corresponding to integer keys
    Hashtable&amp;lt;Integer, String&amp;gt;
        hm = new Hashtable&amp;lt;Integer, String&amp;gt;();

    // Input the values
    hm.put(1, "Geeks");
    hm.put(12, "forGeeks");
    hm.put(15, "A computer");
    hm.put(3, "Portal");

    // Printing the Hashtable
    System.out.println(hm);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Output: &lt;/p&gt;

&lt;p&gt;{15=A computer, 3=Portal, 12=forGeeks, 1=Geeks}&lt;/p&gt;

&lt;h2&gt;
  
  
  Method-2:
&lt;/h2&gt;

&lt;p&gt;With the help of HashMap (A non-synchronized faster implementation of hashing)&lt;/p&gt;

&lt;p&gt;// Java program to create HashMap from an array&lt;br&gt;
// by taking the elements as Keys and&lt;br&gt;
// the frequencies as the Values&lt;/p&gt;

&lt;p&gt;import java.util.*;&lt;/p&gt;

&lt;p&gt;class GFG {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Function to create HashMap from array
static void createHashMap(int arr[])
{
    // Creates an empty HashMap
    HashMap&amp;lt;Integer, Integer&amp;gt; hmap = new HashMap&amp;lt;Integer, Integer&amp;gt;();

    // Traverse through the given array
    for (int i = 0; i &amp;lt; arr.length; i++) {

        // Get if the element is present
        Integer c = hmap.get(arr[i]);

        // If this is first occurrence of element
        // Insert the element
        if (hmap.get(arr[i]) == null) {
            hmap.put(arr[i], 1);
        }

        // If elements already exists in hash map
        // Increment the count of element by 1
        else {
            hmap.put(arr[i], ++c);
        }
    }

    // Print HashMap
    System.out.println(hmap);
}

// Driver method to test above method
public static void main(String[] args)
{
    int arr[] = { 10, 34, 5, 10, 3, 5, 10 };
    createHashMap(arr);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Output: &lt;/p&gt;

&lt;p&gt;{34=1, 3=1, 5=2, 10=3}&lt;/p&gt;

&lt;h2&gt;
  
  
  Method-3:
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;With the help of LinkedHashMap (Similar to HashMap, but keeps order of elements)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;// Java program to demonstrate working of LinkedHashMap&lt;br&gt;
import java.util.*;&lt;/p&gt;

&lt;p&gt;public class BasicLinkedHashMap&lt;br&gt;
{&lt;br&gt;
    public static void main(String a[])&lt;br&gt;
    {&lt;br&gt;
        LinkedHashMap lhm =&lt;br&gt;
                       new LinkedHashMap();&lt;br&gt;
        lhm.put("one", "practice.geeksforgeeks.org");&lt;br&gt;
        lhm.put("two", "code.geeksforgeeks.org");&lt;br&gt;
        lhm.put("four", "quiz.geeksforgeeks.org");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // It prints the elements in same order 
    // as they were inserted    
    System.out.println(lhm);

    System.out.println("Getting value for key 'one': "
                                   + lhm.get("one"));
    System.out.println("Size of the map: " + lhm.size());
    System.out.println("Is map empty? " + lhm.isEmpty());
    System.out.println("Contains key 'two'? "+ 
                              lhm.containsKey("two"));
    System.out.println("Contains value 'practice.geeks"
    +"forgeeks.org'? "+ lhm.containsValue("practice"+
    ".geeksforgeeks.org"));
    System.out.println("delete element 'one': " + 
                       lhm.remove("one"));
    System.out.println(lhm);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Output: &lt;/p&gt;

&lt;p&gt;{one=practice.geeksforgeeks.org, two=code.geeksforgeeks.org, four=quiz.geeksforgeeks.org}&lt;br&gt;
Getting value for key 'one': practice.geeksforgeeks.org&lt;br&gt;
Size of the map: 3&lt;br&gt;
Is map empty? false&lt;br&gt;
Contains key 'two'? true&lt;br&gt;
Contains value 'practice.geeksforgeeks.org'? true&lt;br&gt;
delete element 'one': practice.geeksforgeeks.org&lt;br&gt;
{two=code.geeksforgeeks.org, four=quiz.geeksforgeeks.org}&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>hashing</category>
    </item>
    <item>
      <title>Decision making and looping</title>
      <dc:creator>NANDYALA ANUROOP</dc:creator>
      <pubDate>Tue, 11 May 2021 06:35:01 +0000</pubDate>
      <link>https://dev.to/anuroop123/decision-making-and-looping-9nf</link>
      <guid>https://dev.to/anuroop123/decision-making-and-looping-9nf</guid>
      <description>&lt;p&gt;A normal program is not a sequential execution of expressions or statements one after the other. It will have certain conditions to be checked or it will have certain number of iterations. &lt;/p&gt;

&lt;p&gt;When we have to execute particular set of instructions multiple times or known number of times (iterations), then we use FOR loops or DO/WHILE loops.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;If… Else Statements&lt;br&gt;
For Loops&lt;br&gt;
While and Do/While Loops&lt;br&gt;
    The general syntax for while and do/while loops are given below :&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  If… Else Statements&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;These are the decision making statements.  It is used for checking certain condition to decide which block of code to be executed.  syntax for if..else statement is&lt;/p&gt;

&lt;p&gt;if (condition / s){&lt;br&gt;
    expressions / statements;&lt;br&gt;
} else {&lt;br&gt;
    expressions / statements;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;if (condition / s){&lt;br&gt;
  expressions / statements;&lt;br&gt;
} else if {&lt;br&gt;
  expressions / statements;&lt;br&gt;
} else {&lt;br&gt;
  expressions / statements;&lt;br&gt;
}&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;example :&lt;br&gt;
if (intDivisor == 0) {&lt;br&gt;
  printf ("Warning!: Divisor is Zero!!\n Please re-enter the divisor :");&lt;br&gt;
  scanf ("%d", &amp;amp;intDivisor);&lt;br&gt;
}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;intResult=intDividend / intDivisor;&lt;/p&gt;

&lt;p&gt;If statement can have expressions to be executed when the condition is false. Those expressions are added in the else part of the ‘if’ statement.&lt;/p&gt;

&lt;p&gt;if (condition / s) {&lt;br&gt;
  expressions / statements;&lt;br&gt;
} else {&lt;br&gt;
  expressions / statements;&lt;br&gt;
}&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example :&lt;br&gt;
if (intVal &amp;gt;= 0)&lt;br&gt;
  printf ("You entered a Positive Number!");&lt;br&gt;
else&lt;br&gt;
  printf ("You entered a Negative Number!");&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can have if statement within another if statement, i.e.; we can have nested if statements.&lt;br&gt;
e.g.: –&lt;br&gt;
if (intVal &amp;gt;= 0)&lt;br&gt;
  if (intVal == 0)&lt;br&gt;
    printf ("You entered a Zero!");&lt;br&gt;
  else&lt;br&gt;
    printf ("You entered a Positive Number!");&lt;br&gt;
else&lt;br&gt;
  printf ("You entered a Negative Number!");&lt;/p&gt;

&lt;h1&gt;
  
  
  For Loops:
&lt;/h1&gt;

&lt;p&gt;A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;for (intial_value; condition; increment_factor) {&lt;br&gt;
    statement/s;&lt;br&gt;
  }&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;void main () {&lt;br&gt;
  int intNum; &lt;br&gt;
  printf ("\n First 15 natural numbers are: \n");&lt;br&gt;
  for (intNum = 0; intNum &amp;lt; 15; intNum++) {&lt;br&gt;
    printf ("%d  ", intNum);&lt;br&gt;
  }&lt;br&gt;
}&lt;/p&gt;

&lt;h1&gt;
  
  
  While loop:
&lt;/h1&gt;

&lt;p&gt;A while loop in C programming repeatedly executes a target statement as long as a given condition is true.&lt;br&gt;
Syntax:&lt;br&gt;
while (condition/s){&lt;br&gt;
    Expression / statements;&lt;br&gt;
}&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;void main() {&lt;br&gt;
  int intNum = 0;&lt;br&gt;
  printf("\n Example of WHILE Loop\n");&lt;br&gt;
  printf("First 15 natural numbers are: \n");&lt;br&gt;
  while (intNum &amp;lt; 15){&lt;br&gt;
    printf("%d  ", intNum);&lt;br&gt;
    intNum++;&lt;/p&gt;

&lt;h1&gt;
  
  
  Do/While Loops:
&lt;/h1&gt;

&lt;p&gt;The body of do...while loop is executed once. · If the test expression is true, the body of the loop is executed again and the test expression is evaluated&lt;br&gt;
Syntax:&lt;/p&gt;

&lt;p&gt;do{&lt;br&gt;
  Expression / statements;&lt;br&gt;
} while (condition/s);&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example:&lt;br&gt;
{&lt;br&gt;
  printf("\n Example of DO/WHILE Loop\n");&lt;br&gt;
  printf("First 15 natural numbers in descending order is: \n");&lt;br&gt;
  while (intNum &amp;gt;=0){&lt;br&gt;
    printf("%d  ", intNum--);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;}&lt;/p&gt;

</description>
      <category>loops</category>
      <category>clanguage</category>
    </item>
  </channel>
</rss>
