<?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: Tarun Kumar J</title>
    <description>The latest articles on DEV Community by Tarun Kumar J (@tarunj096).</description>
    <link>https://dev.to/tarunj096</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%2F379136%2Fb56da3e7-4feb-4926-887b-7cfe04d086d4.jpeg</url>
      <title>DEV Community: Tarun Kumar J</title>
      <link>https://dev.to/tarunj096</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tarunj096"/>
    <language>en</language>
    <item>
      <title>Go/Golang - Data Structures ( Arrays,Slices and Maps )</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Wed, 29 Sep 2021 03:17:42 +0000</pubDate>
      <link>https://dev.to/tarunj096/go-golang-data-structures-arrays-slices-and-maps-2ogj</link>
      <guid>https://dev.to/tarunj096/go-golang-data-structures-arrays-slices-and-maps-2ogj</guid>
      <description>&lt;h3&gt;
  
  
  Arrays
&lt;/h3&gt;

&lt;p&gt;An &lt;code&gt;Array&lt;/code&gt; is a collection/sequence of values of a single type. Arrays in &lt;code&gt;Go&lt;/code&gt; are similar to arrays in other languages.&lt;br&gt;
Let's see how to declare an array in Go, Below is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value1&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value2&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also initialize arrays with pre-defined values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="m"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;44&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;55&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;value2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"This is "&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"Golang"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Blog series"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;//Initializing with short variable declaration operator&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access all the elements of an array using for loop. Below is a code snippet :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numArr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;76&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;45&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;33&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;65&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numArr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                   &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Value is :"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;numArr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;len()&lt;/code&gt; function above is used to find the arrays's size.&lt;/p&gt;

&lt;p&gt;Note: Arrays are &lt;strong&gt;passed as values&lt;/strong&gt; to a function. That is we pass a copy of it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Slices
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;Slice&lt;/code&gt; in Go is very similar to an array. Arrays are of fixed size, But slices are &lt;strong&gt;dynamically sized&lt;/strong&gt;.&lt;br&gt;
Slices can double their current size to add more values. Slices store elements of similar type.&lt;/p&gt;

&lt;p&gt;Slices are declared just as an array but they don't specify the size. Below is an example of that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sliceValues1&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; 

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sliceValues2&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add values to the slice we use &lt;code&gt;append()&lt;/code&gt; function. Let's see a code snippet where we initialize a slice and add more values to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;intSlice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;intSlice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intSlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Length : "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intSlice&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c"&gt;/*Prints length of slice*/&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Capacity :"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intSlice&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c"&gt;/*Prints capacity of slice*/&lt;/span&gt;

&lt;span class="n"&gt;intSlice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intSlice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//You can append multiple values too&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intSlice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//Prints slice after appending multiple values&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above snippet &lt;code&gt;len()&lt;/code&gt; gives us the current length of slice &lt;code&gt;cap()&lt;/code&gt; gives us the total capacity of it.&lt;/p&gt;

&lt;p&gt;We can create a slice of a slice by using the below code :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;sliceVal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;60&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;sliceVal1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;sliceVal&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c"&gt;// It creates a slice of 10,20,30,40 &lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sliceVal1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One important note is that Slices are &lt;strong&gt;passed by reference&lt;/strong&gt; in Go.&lt;/p&gt;

&lt;h3&gt;
  
  
  Maps
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Maps&lt;/code&gt; in Go are used to store key-value pairs and It doesn't allow any identical keys.&lt;br&gt;
Let's see how to declare a map in a code snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;animals&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above snippet, The key is of type int and the value is of string type.&lt;/p&gt;

&lt;p&gt;You have to initialize a map when declaring it or else it's a nil Map and you can't add elements to a &lt;strong&gt;nil&lt;/strong&gt; Map. Let's see how to initialize a Map in Go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;animals&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Tiger"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Lion"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Elephant"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="m"&gt;4&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Giraffe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c"&gt;//The comma is a must after the last key&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Map can be created using &lt;code&gt;make()&lt;/code&gt; function. make() function creates an initialized map, Below is a code snippet to create that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;
&lt;span class="n"&gt;prices&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;make&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Item1"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;240&lt;/span&gt;
&lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Item2"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;350&lt;/span&gt;
&lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Item3"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;150&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above prices map can be iterated as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;":&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can remove a key using the built-in &lt;code&gt;delete()&lt;/code&gt; function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nb"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Item1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Point to Note is Maps are &lt;strong&gt;reference types&lt;/strong&gt;. So when a Map is assigned to a variable, If any changes are made in the variable it also changes the Map. &lt;/p&gt;

&lt;p&gt;That's it for this blog ✅.&lt;/p&gt;

&lt;p&gt;For more information, You can always check out the official documentation. &lt;br&gt;
 &lt;a href="https://golang.org"&gt;This &lt;/a&gt; is the official site 💯.&lt;/p&gt;

&lt;p&gt;If you are new to the Go language and you want to check out more,&lt;br&gt;
Below are some resources 🔥.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Free coding exercises(Gophercises) course in Go by John Calhoun. You can check it out &lt;a href="https://gophercises.com"&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A full video course on Go by  &lt;a href="https://www.youtube.com/watch?v=YS4e4q9oBaU"&gt;freecodecamp&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's a course on Codecademy on Go language. You can check it out &lt;a href="https://www.codecademy.com/learn/learn-go"&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Go/Golang Basics - Pointers and Functions</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Sat, 25 Sep 2021 03:59:23 +0000</pubDate>
      <link>https://dev.to/tarunj096/go-golang-basics-pointers-and-functions-27f9</link>
      <guid>https://dev.to/tarunj096/go-golang-basics-pointers-and-functions-27f9</guid>
      <description>&lt;p&gt;A &lt;code&gt;function&lt;/code&gt; is a group of statements that can be used repeatedly in a program. Below is a simple function definition in &lt;code&gt;Go&lt;/code&gt; language :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;helloUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

         &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" Hello, World!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above-defined function helloUser() has a print statement in it and It runs it when we call the function.&lt;/p&gt;

&lt;p&gt;A function starts with the keyword func followed by the function name. Below is a function that is defined with parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 

         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function has two parameters num1 and num2 and there's a return type specified after the parentheses. The return type here is Int. A Go function can return multiple values&lt;/p&gt;

&lt;p&gt;Since the above function has the parameters with the same datatype we can write it as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Note *&lt;/em&gt;: Go uses &lt;code&gt;Pass by value&lt;/code&gt; to pass arguments in a function. It cannot change the arguments within the function that are being passed.&lt;/p&gt;

&lt;p&gt;Below is an example of multiple return values in a Go function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

          &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
          &lt;span class="n"&gt;num2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;
          &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mul&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;addandMultiplyNum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Result after adding is :"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Result after multiplying is :"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;addandMultiplyNum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;num2&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
       &lt;span class="n"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;
       &lt;span class="n"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pointers
&lt;/h3&gt;

&lt;p&gt;As I said above Go uses Pass by value in functions. Go is a &lt;code&gt;Pass by value&lt;/code&gt; language.&lt;br&gt;
It means that it only passes the value of the argument and the argument itself. The changes that take place in function stay within that.&lt;/p&gt;

&lt;p&gt;To change the values we use &lt;strong&gt;Pointers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A Pointer is a variable that is used to store the memory address of another variable. Every time we use a variable we retrieve the value stored at the variable's address. To access the address of the variable we use &lt;code&gt;&amp;amp;&lt;/code&gt; operator.&lt;/p&gt;

&lt;p&gt;Below is the example for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;55&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c"&gt;// Prints the address of num&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To store the addresses we use pointers. The&lt;code&gt;*&lt;/code&gt;operator is used to declare a pointer. &lt;br&gt;
An example of that is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;55&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;pointertoNum&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; 

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pointertoNum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//Prints the address of num&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we'd want to store a different value in the variable, We can access the value stored in the address by the&lt;code&gt;*&lt;/code&gt; operator. That is also called dereferencing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;55&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;pointertoNum&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; 

&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;pointertoNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;45&lt;/span&gt;

&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Prints 45&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To change values that are passed to function, We can use Pointers.&lt;br&gt;
Below is a example for that :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;changeNumtoZero&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numptr&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;  &lt;span class="c"&gt;//The parameter here is pointer to num&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;numptr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Prints 20&lt;/span&gt;
&lt;span class="n"&gt;changeNumtoZero&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;//Pass the address of num&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Prints 0&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's It for this blog ✅.&lt;/p&gt;

&lt;p&gt;For more information, You can always check out the official documentation. &lt;br&gt;
&lt;a href="https://golang.org"&gt;This &lt;/a&gt; is the official site 💯.&lt;/p&gt;

&lt;p&gt;If you are new to the Go language and you want to check out more,&lt;br&gt;
 Below are some &lt;strong&gt;resources&lt;/strong&gt; 🔥.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Free coding exercises(Gophercises) course in Go by John Calhoun. You can check it out &lt;a href="https://gophercises.com"&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A full video course on  &lt;a href="https://www.youtube.com/watch?v=YS4e4q9oBaU"&gt;freecodecamp&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's a course on Codecademy on Go language. You can check it out  &lt;a href="https://www.codecademy.com/learn/learn-go"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>go</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Go/Golang Basics - Variables and Data types</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Thu, 16 Sep 2021 08:05:12 +0000</pubDate>
      <link>https://dev.to/tarunj096/go-golang-basics-variables-and-data-types-1n46</link>
      <guid>https://dev.to/tarunj096/go-golang-basics-variables-and-data-types-1n46</guid>
      <description>&lt;p&gt;Basic data types in Go are:&lt;code&gt;int&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;,&lt;code&gt;complex&lt;/code&gt;,&lt;code&gt;string&lt;/code&gt;,&lt;code&gt;bool&lt;/code&gt;.&lt;br&gt;
Int, Float, and complex are part of the numbers.&lt;/p&gt;

&lt;p&gt;We'll start with Integers.There are two categories, One is signed and other is unsigned integers.Signed integers can be negative but unsigned integers are always positive.Signed int is referred as &lt;code&gt;int&lt;/code&gt; and Unsigned int as &lt;code&gt;uint&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;They are : int8, int16, int32, int64, uint8, uint16, uint32, uint64, int, uint.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

            &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;lengthOfWire&lt;/span&gt; &lt;span class="kt"&gt;uint16&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;36&lt;/span&gt;
            &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;numberOfChocalates&lt;/span&gt; &lt;span class="kt"&gt;int8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; 
            &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;boxlength&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;200&lt;/span&gt;
            &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;450&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is Floating-Point Numbers. They are of two types &lt;code&gt;float32&lt;/code&gt; and &lt;code&gt;float64&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;      &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ratingOfTheProduct&lt;/span&gt; &lt;span class="kt"&gt;float32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;3.5&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the next part is &lt;code&gt;Complex&lt;/code&gt; Numbers. Complex numbers are of two types, complex64 and complex128. The in-built function creates a complex number from its imaginary and real part. Complex numbers can be initialized as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;      &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="kt"&gt;complex64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;complex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="kt"&gt;complex128&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;complex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="m"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If they are printed then, their output would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;2i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;7&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;3i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Boolean&lt;/code&gt;: Boolean data type contains only 1 bit of information. It's either 0 or 1. 0 denotes false and 1 denotes true.&lt;/p&gt;

&lt;p&gt;They can be initialized as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;     &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;isCodingFun&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last data type is a &lt;code&gt;string&lt;/code&gt;. A string stores sequence of characters and it must be surrounded with double-quotes. They can be initialized as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;     &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hi, Welcome to Golang Blog Series"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can concatenate two strings by using the &lt;code&gt;+&lt;/code&gt; operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;     &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;nameOfMovie&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Avengers Endgame "&lt;/span&gt;

     &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;concatStr&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nameOfMovie&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;"is one of the greatest superhero movies."&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;Variables in the Go language hold a value even before we assign anything to it. They are default values. All the numeric variables have 0 as default and string variables have&lt;code&gt;""&lt;/code&gt;. Boolean variables have false as default value.&lt;/p&gt;

&lt;p&gt;You can declare a variable without stating its type by &lt;code&gt;:=&lt;/code&gt; (short declaration operator ). For example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;
         &lt;span class="n"&gt;nameOfMovie&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Avengers Endgame"&lt;/span&gt;
         &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;15&lt;/span&gt;
         &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;3.7&lt;/span&gt;
         &lt;span class="n"&gt;isClimateChangeReal&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go also allows us to declare multiple variables in a single line. An Example of that is :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;       &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;20&lt;/span&gt;

       &lt;span class="n"&gt;nameOfStreet&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sure&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Abbey road"&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt; 
      &lt;span class="c"&gt;//'nameOfStreet' is type 'string' and 'sure' is type 'bool'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it for this blog ✅.&lt;/p&gt;

&lt;p&gt;For more information, You can always check out the Official documentation.  &lt;a href="https://golang.org"&gt;This&lt;/a&gt; is the official site 💯.&lt;/p&gt;

&lt;p&gt;If you are new to the &lt;code&gt;Go&lt;/code&gt; language and you want to check out more, Below are some resources 🔥.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A full video course on  &lt;a href="https://www.youtube.com/watch?v=YS4e4q9oBaU"&gt;freecodecamp&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's a Course on Codecademy on Go language. You can check it out  &lt;a href="https://www.codecademy.com/learn/learn-go"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Go/Golang Basics</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Wed, 15 Sep 2021 02:51:01 +0000</pubDate>
      <link>https://dev.to/tarunj096/go-golang-basics-246c</link>
      <guid>https://dev.to/tarunj096/go-golang-basics-246c</guid>
      <description>&lt;p&gt;&lt;strong&gt;Go&lt;/strong&gt; is Open Source Programming language that is  &lt;code&gt;statically typed&lt;/code&gt; . Although it is statically typed, It's so fast that it feels like it's an Interpreted language. &lt;/p&gt;

&lt;p&gt;So let's start with the basics. As Go is a Compiled language, Its Code has to be converted to an executable/binary file. Go has a compiler that translates the code into a binary file.&lt;/p&gt;

&lt;p&gt;If your file's name was helloworld.go then to compile it on the terminal, The command would look like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt; &lt;span class="n"&gt;helloworld&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command would create a "helloworld" file. To execute that, call &lt;code&gt;./helloworld&lt;/code&gt;  in the terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="o"&gt;./&lt;/span&gt;&lt;span class="n"&gt;helloworld&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's a run command that both compiles and executes the code. Although the run command will not create a binary file.&lt;/p&gt;

&lt;p&gt;For example to run the command on helloworld.go file, It would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;helloworld&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Go program should have a package declaration. After the package declaration, We have import statement right below it. It looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the package name has to be enclosed in &lt;code&gt;double quotes&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;The functions in Go are declared with &lt;code&gt;func&lt;/code&gt; keyword and that is followed by name of the function.&lt;br&gt;
Let's see a basic program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" Hello World! "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above program in function main we have used the &lt;code&gt;fmt&lt;/code&gt; package which helps us call Println to print.&lt;/p&gt;

&lt;p&gt;To run the command we use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="k"&gt;go&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would print the message "Hello World!".&lt;/p&gt;

&lt;p&gt;In Go language, the main package is a special package which is used with the programs that are executable and this package contains main() function. Go automatically calls the main function and there is no need to explicitly call it.&lt;/p&gt;

&lt;p&gt;You can use &lt;strong&gt;go doc&lt;/strong&gt; on the command line for more information about the packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command gives us information about fmt package. &lt;br&gt;
For more specific information you could use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And Lastly, For more information about Go lang ,You can always check the documentation.   &lt;a href="https://golang.org"&gt;&lt;strong&gt;&lt;em&gt;This&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; is the official site 💯.&lt;/p&gt;

&lt;p&gt;If you are learning Go language and would want to know more, Below are some resources 🔥.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Watch a video course on &lt;a href="https://www.youtube.com/watch?v=YS4e4q9oBaU"&gt; &lt;strong&gt;freecodecamp&lt;/strong&gt;&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's a free course on Codecademy too. You can check it out  &lt;a href="https://www.codecademy.com/learn/learn-go"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>go</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>ArrayList In Java.</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Tue, 15 Sep 2020 05:52:03 +0000</pubDate>
      <link>https://dev.to/tarunj096/arraylist-in-java-27l4</link>
      <guid>https://dev.to/tarunj096/arraylist-in-java-27l4</guid>
      <description>&lt;p&gt;Continuing my Blogs on &lt;a href="https://www.java.com/en/"&gt; Java &lt;/a&gt; Data Structures, The next topic is &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html"&gt; ArrayLists  &lt;/a&gt; . So, Let's know about ArrayLists and how it essentially works. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;ArrayList&lt;/code&gt; is another tool in Java to store a large number of values that are of the same type.&lt;br&gt;
In a high-level context,  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They are a dynamic-array implementation of  &lt;a href="https://docs.oracle.com/javase/7/docs/api/java/util/List.html"&gt;List &lt;/a&gt; Interface.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So when we create an ArrayList, And we add or remove elements from the list, It automatically changes the size of the array by itself, that is what a dynamic array means.&lt;/p&gt;

&lt;p&gt;ArrayList contains various methods for adding, removing, and retrieving elements from a List.&lt;br&gt;
So let's first see how to declare an ArrayList.&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.ArrayList;

public class ArrayListEx{
            public static void main(String[] args){
                ArrayList&amp;lt;String&amp;gt; names = new ArrayList&amp;lt;&amp;gt;();                     
       }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in the above code, we import the ArrayList first by  &lt;code&gt;java.util.ArrayList&lt;/code&gt; and then we declare the ArrayList  by &lt;code&gt;ArrayList&amp;lt;String&amp;gt; names = new ArrayList&amp;lt;&amp;gt;();&lt;/code&gt; which creates a list called names which is of type &lt;strong&gt;String&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The general syntax is:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;Type&amp;gt; list = new ArrayList&amp;lt;&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Type is basically the type of values stored in the list such as Integer, Boolean, Double, etc.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding, Removing, and Retrieving values from the ArrayList.
&lt;/h3&gt;

&lt;p&gt;To &lt;strong&gt;Add&lt;/strong&gt; value into an Arraylist, we use the &lt;code&gt;add()&lt;/code&gt; method. Let's see it by example.&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.ArrayList;

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

            ArrayList&amp;lt;String&amp;gt; namesList = new ArrayList&amp;lt;String&amp;gt;();  //Creates a ArrayList of name "namesList"
            namesList.add("Tarun");   
            namesList.add("Jim");
            namesList.add("John");
            System.out.println("The List is: "+namesList);    //prints the list

           /*Output:
              The List is: [Tarun, Jim, John]
           */
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can add value in the list at a particular &lt;code&gt;index&lt;/code&gt;, That is by mentioning the index value first and then the element next in the add method. Below is an example of that:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Note: Using the same list as above
      namesList.add(1,"Jake");   
//So now the ArrayList contains another value at index 1.
      System.out.println(namesList);

    //The Output is : [Tarun, Jake, Jim, John]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To &lt;strong&gt;retrieve&lt;/strong&gt; a value from the ArrayList we use the &lt;code&gt;get()&lt;/code&gt; method. To retrieve an element at index 2 in the "namesList" ArrayList we use &lt;code&gt;namesList.get(2)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    System.out.println(namesList.get(2));   // Prints the element at index 2.
    // Output :  Jim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And To &lt;strong&gt;remove&lt;/strong&gt; elements from an ArrayList, we use the &lt;code&gt;remove()&lt;/code&gt; method. We can remove an element by giving the index or by the value itself as the parameter.&lt;br&gt;
Let's see an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    namesList.remove("Jim");  //Removing the String Jim 
    namesList.remove(1);  //Removing the value at index 1
    System.out.println(namesList);

//Output : [Tarun, John]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, these aren't the only methods in the ArrayList but they are the most used ones. There are many methods such as the &lt;code&gt;clear()&lt;/code&gt; method, which removes all the elements from the list. &lt;code&gt;contains()&lt;/code&gt; method, which checks if the given element is in the list.&lt;/p&gt;

&lt;p&gt;If you wish to explore other methods, You can visit the official &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html"&gt; Documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you got a basic understanding of what an &lt;code&gt;ArrayList&lt;/code&gt; is and how it works. &lt;/p&gt;

&lt;p&gt;See you in the next article and until then, Happy Coding 🙂⚡️. &lt;/p&gt;

</description>
      <category>java</category>
      <category>arraylists</category>
      <category>100daysofcode</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Arrays in Java.</title>
      <dc:creator>Tarun Kumar J</dc:creator>
      <pubDate>Wed, 26 Aug 2020 08:16:33 +0000</pubDate>
      <link>https://dev.to/tarunj096/arrays-in-java-1ng4</link>
      <guid>https://dev.to/tarunj096/arrays-in-java-1ng4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hello Everyone 💫!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I mentioned I will write about Java in my previous article and I was thinking which topic should I choose, And I finally chose ** Data Structures ** in Java. &lt;/p&gt;

&lt;p&gt;This article would help every beginner studying in Java and I hope this helps you understand Arrays in Java easily. Another reason being, It would help me get my understanding strong as well.&lt;br&gt;
So let's start discussing &lt;strong&gt;Arrays&lt;/strong&gt; in Java.&lt;/p&gt;
&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;p&gt;An array is a data structure that stores elements of the same data type at contiguous(next to or adjacent) memory locations.&lt;/p&gt;

&lt;p&gt;So lets first find out how to &lt;strong&gt;create&lt;/strong&gt; an array. &lt;/p&gt;

&lt;p&gt;The below code creates an array of 10 integers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = new int[10];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create an array to hold 100 names:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = new String[100];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another way of creating an array is by initiating it with values when you declare the array.&lt;br&gt;
The code down creates an array with 5 integers and initiates it with values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] number = { 8, 10, 26, 9, 96 };      // It creates an array of 5 integers.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also initialize an array of strings in the same way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = { "Tarun", "Louis" , "John" };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Java, the first index of an array starts with 0. So if the length of an array is 5 then the last element's index is 4.The elements are also called values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assigning and printing the elements
&lt;/h2&gt;

&lt;p&gt;An element of an array is referred to by its index. In the below code we create an array of two numbers and assign values to the indices 0 and 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = new int[2];

numbers[0] = 18;
numbers[1] = 26;

System.out.println(numbers[0]);
System.out.println(numbers[1]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; You can find the size of the array by length variable. We can get that by name of the array dot length, ie by ** numbers. length **&lt;br&gt;
and If we print that It will give us the size of an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = new int[2];
System.out.println(numbers.length);   // It will print 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we write the index outside of an array ie bigger than the index size, We get an &lt;strong&gt;ArrayIndexOutOfBoundsException&lt;/strong&gt;, ie It tells us that the array doesn't contain the given index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] arrayOfNames = { "Hello" , "there"}; //The array contains only two elements ie index 0 and 1.

System.out.println(arrayOfNames[3]); //This will give us an ArrayIndexOutOfBoundsException.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Iterating over an Array
&lt;/h2&gt;

&lt;p&gt;This means accessing each element of an array one by one. I'd help you understand that with an example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = new String[3];
names[0] = "Tarun";
names[1] = "Jonathan";
names[2] = "Vicky";

System.out.println("The length of the array is "+names.length+"."); 

//The below while loop prints every element of the array by iterating over it.
int index = 0;
while(index&amp;lt;names.length){
      System.out.println(names[index]);
      index = index + 1;
}

/* 

The Output of the program will be:
The length of the array is 3.
Tarun
Jonathan
Vicky

*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code finds the length of the String array and prints it, And then it iterates over the array and prints out every string element one by one.&lt;/p&gt;

&lt;p&gt;Finally, I'd like to say that If anyone wants to learn more in Java, There are free courses out there.You can choose whichever you like and start learning, The best ones I've found are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://www.codecademy.com/learn/learn-java/"&gt;Codecademy&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://practice.geeksforgeeks.org/batch/fork-java"&gt;GeeksForGeeks&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Youtube channel - &lt;a href="https://www.youtube.com/channel/UC_fFL5jgoCOrwAVoM_fBYwA/featured"&gt;Alex Lee&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Youtube channel - &lt;a href="https://youtu.be/eIrMbAQSU34"&gt;Programming with Mosh&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks for reading! Hope you like it 🙂.&lt;/p&gt;

&lt;p&gt;See you in the next article until then, Happy Coding ⚡️! &lt;/p&gt;

&lt;p&gt;PS:&lt;br&gt;
&lt;em&gt;If you find any mistakes in the above article/blog, Please comment it out, So that I would make the edits.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>100daysofcode</category>
      <category>arrays</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
