<?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: Pankaj Singh</title>
    <description>The latest articles on DEV Community by Pankaj Singh (@pankaj_singhr).</description>
    <link>https://dev.to/pankaj_singhr</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%2F780870%2Fb6e2bf22-9a0b-4edc-869c-1b9972bea26d.JPG</url>
      <title>DEV Community: Pankaj Singh</title>
      <link>https://dev.to/pankaj_singhr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pankaj_singhr"/>
    <language>en</language>
    <item>
      <title>React Logo Using Only 2 Div In Pure CSS</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Fri, 04 Feb 2022 13:55:00 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/react-logo-using-only-2-div-in-pure-css-2o2e</link>
      <guid>https://dev.to/pankaj_singhr/react-logo-using-only-2-div-in-pure-css-2o2e</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/pankaj-singhr/embed/zYPBJdK?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>css</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Google Logo Using Single Div In Pure CSS</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Fri, 04 Feb 2022 13:52:58 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/google-logo-using-single-div-in-pure-css-1dfc</link>
      <guid>https://dev.to/pankaj_singhr/google-logo-using-single-div-in-pure-css-1dfc</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/pankaj-singhr/embed/JjOKabE?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>Lightning Effect Using CSS Animation</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Fri, 04 Feb 2022 13:51:06 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/lightning-effect-using-css-animation-4h3</link>
      <guid>https://dev.to/pankaj_singhr/lightning-effect-using-css-animation-4h3</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/pankaj-singhr/embed/dyZXQLO?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>css3</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>🎯 Objects in JavaScripts</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Sat, 22 Jan 2022 14:38:21 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/objects-in-javascripts-183h</link>
      <guid>https://dev.to/pankaj_singhr/objects-in-javascripts-183h</guid>
      <description>&lt;p&gt;In simple words objects is the collection of name-value pairs. Objects is JavaScript are same as dictionaries in Python , hashtable in c and c++ and hashmap in Java.&lt;br&gt;
The "name" part is a JavaScript string, while the value can be any JavaScript value &lt;/p&gt;

&lt;p&gt;There are two ways of creating the object&lt;br&gt;
1 - using object literal (more convenient)&lt;br&gt;
2 - using new keyword&lt;br&gt;
👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nTp1-YH_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zapwnctotb7o8zein49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nTp1-YH_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zapwnctotb7o8zein49.png" alt="Image description" width="880" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A simple example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hsyz3oAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5i8fw8apklcz3emnlbj8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hsyz3oAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5i8fw8apklcz3emnlbj8.png" alt="Image description" width="880" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>🎯 10 most useful string methods in Java </title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Wed, 19 Jan 2022 17:55:20 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/10-most-useful-string-methods-in-java-4lag</link>
      <guid>https://dev.to/pankaj_singhr/10-most-useful-string-methods-in-java-4lag</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction on Strings&lt;/strong&gt;&lt;br&gt;
String is an object that represents sequence of char values. Strings are immutable in Java.There are two ways to create string in Java&lt;br&gt;
1 - By String literal&lt;br&gt;
2 - By new keyword&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnhtqlt9diwdjzsoy9f2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnhtqlt9diwdjzsoy9f2.png" alt="Method to create strings in java"&gt;&lt;/a&gt;&lt;br&gt;
📌 Note: String literal create no new object if it exists already in the string constant pool (SCP) which is a special place for all strings in heap memory. Create string of same object using new keyword.This will create new object outside the string pool if it already exist in it &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;1 - indexOf()&lt;/strong&gt;&lt;/em&gt; used to find characters and substrings in a string. It returns the index of first occurrence from left of the passed string or character&lt;br&gt;
syntax - public int indexOf​(String str, int fromIndex)&lt;br&gt;
str - substring to be search&lt;br&gt;
fromIndex - search begin from this index&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mlymwr4yvhctei85dlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0mlymwr4yvhctei85dlm.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;2 - toCharArray()&lt;/em&gt;&lt;/strong&gt; used to form a character array of a string&lt;br&gt;
syntax - public char[] toCharArray()&lt;/p&gt;

&lt;p&gt;▶️Example : check if string is palindrome of not&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8y0pfbohgg4p164kf3c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq8y0pfbohgg4p164kf3c.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
3 - charAt() Used to find the character at particular index&lt;br&gt;
syntax - public char charAt​(int index)&lt;/p&gt;

&lt;p&gt;▶️ Example : count no. of spaces in the string&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bfi1iqqyzuxya9n7u8a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0bfi1iqqyzuxya9n7u8a.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;4 - concat()&lt;/em&gt;&lt;/strong&gt; Used to concatenate two strings&lt;br&gt;
syntax - public String concat(String str)&lt;/p&gt;

&lt;p&gt;▶️ Example : concatenate last name and firstname&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj66h9pvbfxjy1fi2winb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj66h9pvbfxjy1fi2winb.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;5 - replace()&lt;/em&gt;&lt;/strong&gt; Used for replacing characters and substrings in a string&lt;br&gt;
syntax - public String replace​(char oldChar, char newChar)&lt;/p&gt;

&lt;p&gt;▶️ Example : remove all white spaces from the string&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm0gvz9i10lwst3gs4qyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm0gvz9i10lwst3gs4qyq.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;6 - substring()&lt;/em&gt;&lt;/strong&gt; Used to extract a portion of a string from original string&lt;br&gt;
syntax - public String substring​(int beginIndex, int endIndex)&lt;/p&gt;

&lt;p&gt;▶️Example : print first 3 character of a string&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0demkdneym2sdylozj73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0demkdneym2sdylozj73.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;7 - split()&lt;/em&gt;&lt;/strong&gt; Used to breaks a given string around matches of the given regular expression.After splitting against the given regular expression, this method returns a char array&lt;br&gt;
syntax - public String[] split​(String regex, int limit)&lt;br&gt;
limit : number of strings return after split&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqh2zu28ks5pt2w0ttew8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqh2zu28ks5pt2w0ttew8.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;8 - compareTo()&lt;/em&gt;&lt;/strong&gt; It compares the given string with the current string lexicographically. It returns a positive number, negative number, or 0&lt;br&gt;
if s1 &amp;gt; s2, returns +ve number&lt;br&gt;
if s1 &amp;lt; s2, returns -ve number&lt;br&gt;
if s1 == s2, returns 0&lt;br&gt;
syntax : public int compareTo(String anotherString)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1dcj5mldefzuea7uq2qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1dcj5mldefzuea7uq2qa.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;9 - strip()&lt;/em&gt;&lt;/strong&gt; To eliminate all trailing and leading whitespaces from the given string&lt;br&gt;
syntax - public String strip()&lt;br&gt;
▶️ Example&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftduzzzth1gbi0nttv2ym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftduzzzth1gbi0nttv2ym.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;10 - valueOf()&lt;/em&gt;&lt;/strong&gt; Used to return string representation of passed argument&lt;br&gt;
syntax - public static String valueOf​(char[] data)&lt;br&gt;
Note : valueOf() has many overloaded variants that aid in the conversion of almost any primitive form to string&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajrpyixwnzmspcsemos9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fajrpyixwnzmspcsemos9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>🎯 Type Coercion in JavaScript</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Wed, 19 Jan 2022 10:23:08 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/type-coercion-in-javascript-23lo</link>
      <guid>https://dev.to/pankaj_singhr/type-coercion-in-javascript-23lo</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Type Coercion is process of automatic or implicit conversion of value from one data type to another. Conversion from Number to String , String to Number, Boolean to Number and so on. Type coercion occurs when different types of operators are applied to the values&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Number to String&lt;/strong&gt; : Anything added to string first JavaScript convert it into string and then concatenates both the strings.&lt;br&gt;
Note : It occur only with "+" operator&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_JN6qMIC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsfcdg249558eyalmv7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_JN6qMIC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsfcdg249558eyalmv7t.png" alt="Image description" width="880" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;String to Number&lt;/strong&gt; : when operation like subtraction( - ), multiplication( * ), division( / ), modulus (%) is performed first JavaScript convert it into number then apply these operations&lt;br&gt;
Note : The string should be a Number&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H_Vg5yvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxspludqjsl5rfke3xo4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H_Vg5yvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxspludqjsl5rfke3xo4.png" alt="Image description" width="880" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Boolean to Number&lt;/strong&gt; : when a boolean is added to a Number, boolean value is converted to number as 0 for "false" and 1 for "true"&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--efcLhXn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5s0ayt0y265mcg1kow0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--efcLhXn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5s0ayt0y265mcg1kow0.png" alt="Image description" width="880" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Equality Operator&lt;/strong&gt; : The equality ( == ) is used to compare value irrespective of their type. This happen by coercion of Non-Number to Number data type&lt;br&gt;
Note : To avoid type coercion, use the triple-equals operator ( === )&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nB1Z0hIy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dswso7qg4mg7csr6ujo6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nB1Z0hIy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dswso7qg4mg7csr6ujo6.png" alt="Image description" width="880" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Binary Search Algorithm</title>
      <dc:creator>Pankaj Singh</dc:creator>
      <pubDate>Sat, 01 Jan 2022 18:12:40 +0000</pubDate>
      <link>https://dev.to/pankaj_singhr/binary-search-in-best-way-2ee0</link>
      <guid>https://dev.to/pankaj_singhr/binary-search-in-best-way-2ee0</guid>
      <description>&lt;p&gt;What is binary search?&lt;br&gt;
Binary search is one of the searching algorithm used to find element in sorted array in Logarithmic running time complexity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Binary search can only be applied in sorted array&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why binary search is better then linear search&lt;/strong&gt;&lt;br&gt;
Binary search has O(log(n)) logarithmic time complexity and linear search has O(n) linear time complexity     &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Binary Search Work&lt;/strong&gt;&lt;br&gt;
Binary search use divide and conquer strategy to search element in given array. Binary search divide the searching area into exact half in each pass.&lt;/p&gt;

&lt;p&gt;start : it store the value of starting index&lt;br&gt;
end : it stores the value of ending index&lt;br&gt;
mid : it stores the value of middle index&lt;/p&gt;

&lt;p&gt;start = 0&lt;br&gt;
end = array_length -1&lt;br&gt;
mid = (start + end)/2 // but that's not good practice&lt;br&gt;
(start + end) can sometime exceed the integer limit&lt;/p&gt;

&lt;p&gt;mid = start + (end - start)/2 // this is the correct way&lt;/p&gt;

&lt;p&gt;Suppose at first we have an array nums = { 1, 2, 4, 8, 10, 50, 70, 88, 100 } (note here array is sorted) and your target element is 70.&lt;br&gt;
First check if middle element of array is equal to target or not. If it's equal then return middle index or mid. If not then check if target is smaller or bigger then middle element. &lt;br&gt;
If target is smaller then middle element reduce the search space, end = mid -1. Now new search space is (start, mid -1).&lt;br&gt;&lt;br&gt;
If target is bigger the middle element reduce the search space, start = mid +1. Now new search space is (mid+1, end).&lt;/p&gt;

&lt;p&gt;Hence, at each pass the search space will reduce into half until start &amp;lt;= end. If start became greater then end, the loop will break&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Algorithm&lt;/strong&gt;&lt;br&gt;
Binary search in Java&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.Arrays;  

public class BinarySearch {
    public static void main(String[] args) {

        int[] nums = { 1, 2, 3, 19, 29, 40, 60, 100 };
        int target = 40;

        System.out.println(Arrays.toString(nums));
        System.out.println(binarySearch(nums, target));
    }

    static int binarySearch(int[] nums, int target) {

        int start = 0;
        int end = nums.length - 1;

        while (start &amp;lt;= end) {

            int mid = start + (end - start) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (target &amp;lt; nums[mid]) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }

        }

        return -1;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
