<?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: Chetan garg</title>
    <description>The latest articles on DEV Community by Chetan garg (@ch8n).</description>
    <link>https://dev.to/ch8n</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%2F441421%2F0d386966-f9df-412f-8df0-22dca9b9b6e9.png</url>
      <title>DEV Community: Chetan garg</title>
      <link>https://dev.to/ch8n</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ch8n"/>
    <language>en</language>
    <item>
      <title>Untangle your String on Java/Kotlin</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Sun, 15 May 2022 07:00:04 +0000</pubDate>
      <link>https://dev.to/ch8n/untangle-your-string-on-javakotlin-2eke</link>
      <guid>https://dev.to/ch8n/untangle-your-string-on-javakotlin-2eke</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Originally Posted on https://chetangupta.net/strings/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In any Programming languages to perform any kind of computation you always work with Numeric(Int, float, double etc), Boolean and Strings kind of data. They are said to be core or primitive data types which you need even for creating complex structures/classes, and know these in detail would always make help you design better code, and choose correct combination of data to get accurate outputs from your functions/programs.&lt;/p&gt;

&lt;p&gt;In this Article we will be diving deep into concept of String. Understand how they work in Java, and what all operations you can perform on them, so without any dues lets get started!&lt;/p&gt;

&lt;h1&gt;
  
  
  What is a string in java?
&lt;/h1&gt;

&lt;p&gt;String?, first question that should pop into you mind is what are they? and how do they look like? and answer from them are quiet simple, just like in our English Grammer, String are nothing but collections are some characters (alphabets and symbols) put together. It doesn't a string that you make sense or not, till is a group of characters its a string. For example “This is a sample String”, or even “zxczxvc adsad qwe” is also a string. &lt;/p&gt;

&lt;p&gt;Different programming languages have different way to represent string, for example some represent it like ‘hello world’ or “hello world”, point to be noted is that string can start from single quotes - ‘ or double Quotes - “”. Also by Language design, there is a possibility language doesn't support string types directly, they might support Character as the primitive type and Strings could be formed with combination of these Characters. If a Language supports Character type then character always starts with single quotes and String will Start with double quotes.&lt;/p&gt;

&lt;p&gt;Anyways enough with the background, coming back to the language we are here to learn which is TADA… Java, String here is not a primitive datatype, even thou it comes packed with the language. Java Supports Character type ie. &lt;code&gt;char&lt;/code&gt; data type.  lets look at its example :&lt;/p&gt;

&lt;p&gt;Example of Character type :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char thisIsa = 'a';
char thisIsA = 'A';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just for your information &lt;code&gt;thisIsa&lt;/code&gt; is not equal to &lt;code&gt;thisIsA&lt;/code&gt;. There is lot to learn about character we wont be digging deep into it (you can learn more about them from here → &lt;a href="https://chetangupta.net"&gt;https://chetangupta.net&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Example of String type :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String thisIsA = "A";
    String thisIsa = "a";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same go there &lt;code&gt;thisIsa&lt;/code&gt; is not equal to &lt;code&gt;thisIsA&lt;/code&gt;, as Strings are case sensitive. hope you got the gist and some background about strings now…&lt;/p&gt;

&lt;p&gt;If so, riddle me this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    char thisIsA = 'A';
    String thisIsAlsoA = "A";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we have said String are collection of sequence of Character will String variable &lt;code&gt;thisIsAlsoA&lt;/code&gt; is equal to &lt;code&gt;thisIsA&lt;/code&gt;? If your curious enough think, if you couldn't find the stick around till the end of the article… &lt;/p&gt;

&lt;h1&gt;
  
  
  How to create a string object?
&lt;/h1&gt;

&lt;p&gt;Let’s go a layer deep in String creation process in Java. The way we have created String using double quotes is called creating &lt;code&gt;String Literal&lt;/code&gt;.  &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 plaintext"&gt;&lt;code&gt;    String a = "A";
    String greet = "Hello World!";
    String pokemon = "Pikachu";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other way to create it is using &lt;code&gt;String Object&lt;/code&gt;, since we know in Java object creation is done using &lt;code&gt;new&lt;/code&gt; operator thus we will create string like &lt;code&gt;String apple = new String(&lt;/code&gt;&lt;code&gt;"&lt;/code&gt;&lt;code&gt;apple&lt;/code&gt;&lt;code&gt;"&lt;/code&gt;&lt;code&gt;);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Some more example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String a = new String("A");
    String greet = new String("Hello World!");
    String pokemon = new String("Pikachu");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might think what is the difference? and also why should I create it using Object method, look more lengthy?  Well that you need to understand what actually is happening under the hood in Java memory model. &lt;/p&gt;

&lt;p&gt;When we create String Literal, JVM looks in the String Pool to check same value already exist or not. If found it would return the object reference, if not then it create new string object with given value and stores in String pool. &lt;/p&gt;

&lt;p&gt;P.S : To learn more about String Pool checkout &lt;a href="https://chetangupta.net"&gt;https://chetangupta.net&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And When we create object using &lt;code&gt;new&lt;/code&gt; operator, then two things happen, the string value that we passed would check and placed in String pool, but the object of String is created into heap memory. Thus this method would take longer time to execute, other side to keep in mind is that it will construct a new object every time.&lt;/p&gt;

&lt;p&gt;Okay, knowing this background is good but how does it explain the &lt;code&gt;new&lt;/code&gt; operator use case ?&lt;br&gt;
Let’s understand :&lt;/p&gt;

&lt;p&gt;A String literal is a String Object, but a String Object is not always a String literal. Literal also represents fixed values i.e. constants, this means String literals once created cannot be modified thus its often said that Java Strings are immutable. we will discuss more about them later. But String Object is different its is designed to be mutated. &lt;/p&gt;

&lt;p&gt;Thus whenever we are dealing string with requires lot of updation we will prefer String Objects over String Literals.&lt;/p&gt;

&lt;p&gt;Always prefer to use &lt;code&gt;StringBuffers&lt;/code&gt; or &lt;code&gt;StringBuilders&lt;/code&gt; to make String Objects that are required lots of modifications. Go for &lt;code&gt;StringBuilders&lt;/code&gt; cause they are modern than StringBuffers and have more functionality.&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 plaintext"&gt;&lt;code&gt;    StringBuilder greetBuilder = new StringBuilder("");

    greetBuilder.append("hello");
    greetBuilder.append(" ");
    greetBuilder.append("World");
    greetBuilder.append("!");

    String greet = greetBuilder.toString();
    System.out.println(greet) // output : hello World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hoping you now have understanding of the role of String Objects vs String Literals.&lt;/p&gt;

&lt;h1&gt;
  
  
  Strings Operations and Methods :
&lt;/h1&gt;

&lt;p&gt;Now here comes the interesting part, let’s explore what the possible operation we can perform over String data-type :&lt;/p&gt;

&lt;h2&gt;
  
  
  Length of String:
&lt;/h2&gt;

&lt;p&gt;If you want to know the length of the string i.e. total number of characters int the String, then use function &lt;code&gt;length()&lt;/code&gt; over string example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String apple = "Apple";
    println(apple.length()); // output --&amp;gt; 5
Character at Index : 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since String is a sequence of character we can get character according to a given index. So we can get character at a index using &lt;code&gt;charAt(index)&lt;/code&gt;&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 plaintext"&gt;&lt;code&gt;    // if we want to get `l` from string apple then
    String apple = "Apple";
    println(apple.charAt(3)); // output --&amp;gt; `l`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note : Do understand that Strings are immutable i.e. you can read value at index but cannot update value on the given index, i.e there is not &lt;code&gt;setCharAt(index)&lt;/code&gt; like function on String.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concatenation/Adding of Strings :
&lt;/h2&gt;

&lt;p&gt;We can add two string i.e. also called Concatenation into single string using &lt;code&gt;concat()&lt;/code&gt; function .&lt;br&gt;
Note : the new concatenated string that we get after operation will be new string, cause String are immutable.&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 plaintext"&gt;&lt;code&gt;    String apple = "Apple";
    String orange = "Orange";
    println(apple.concat(orange)); // output --&amp;gt; AppleOrange
    println(orange.concat(apple)); // output --&amp;gt; OrangeApple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SubString :
&lt;/h2&gt;

&lt;p&gt;Substring means taking a part of string based on given indexes. There are two overloaded function method for this :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;subString(int startIndex) : String&lt;/code&gt; : it will return string from start index to end of string&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;subString(int startIndex, int endIndex):String&lt;/code&gt;  : it will return string from start index to the end index &lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String orange = "Orange";
    println(orange.substring(/*StartIndex*/4)); // output --&amp;gt; ge
    println(orange.substring(/*StartIndex*/1,/*EndIndex*/5)); // output --&amp;gt; rang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Contains :
&lt;/h2&gt;

&lt;p&gt;We use Contains to check if String contains another string or not.  Note: in background it checks for CharSequence for faster evaluation than check each words. (learn more about that from here: &lt;a href="https://chetangupta.net"&gt;https://chetangupta.net&lt;/a&gt;.&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 plaintext"&gt;&lt;code&gt;    String orange = "Orange";
    println(orange.contains("range")); // output --&amp;gt; true
    println(orange.contains("apple")); // output --&amp;gt; false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Join Strings :
&lt;/h2&gt;

&lt;p&gt;Join as name suggest it would join two strings, but you might wonder what is the difference between join and concat? &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Just look the parameters they are receiving, for Join you can transfer ‘n’ number for strings but for concat it would work only two strings, &lt;/li&gt;
&lt;li&gt;Join as ability to provide delimiter/separator i.e. symbol to use when it is merging the String.&lt;/li&gt;
&lt;li&gt;Unlike concat, Join is a static function over String class .&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String apple = "Apple";
    String orange = "Orange";
    String berry = "StrawBerries";
    String seperator = "|";
    println(String.join(seperator,apple,orange,berry)); 
    // output --&amp;gt; Apple|Orange|StrawBerries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Comparing to Strings:
&lt;/h2&gt;

&lt;p&gt;Just for your knowledge when we perform a comparing operation, we are censored wether two items are equal, first item is greater than(&amp;gt;) second item or first item is smaller than(&amp;lt;) second item.&lt;/p&gt;

&lt;p&gt;In Programming, comparison function returns integer value to represent same scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if item1 == item2 then returns 0,
    if item1 &amp;gt; item2 then returns 1,
    if item1 &amp;lt; item2 then returns -1,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In String, these comparison is lexicographically(dictionary order) based i.e&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if string1 == string2 then returns 0
    if string1 &amp;gt; string2 then returns 1, (string 1 comes ahead in dictinoary order)
    if string1 &amp;lt; string2 then returns -1, (string 2 comes ahead in dictinoary order)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Java, we have two functions for comparing string in Java.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;compareTo()&lt;/code&gt; : This compares two string but is case sensitive.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;compareToIgnoreCase()&lt;/code&gt; : This compares two string but is case in-sensitive.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lets see example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // case sensitive comparison
    String apple = "Apple";
    println(apple.compareTo("Apple")); // output  --&amp;gt; 0
    println(apple.compareTo("apple")); // output  --&amp;gt; -32

    // case in-sensitive comparison
    String apple = "Apple";
    println(apple.compareToIgnoreCase("Apple")); // output  --&amp;gt; 0
    println(apple.compareToIgnoreCase("apple")); // output  --&amp;gt; 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Casing in String :
&lt;/h2&gt;

&lt;p&gt;We can control casing of our String character using two function :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;toUpperCase()&lt;/code&gt; : this function upper case all of the characters in out string,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toLowerCase()&lt;/code&gt;: similarly this function lower case all of the characters in out string.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String apple = "ApPlE";
    println(apple); // output --&amp;gt; ApPlE
    println(apple.toUpperCase()); // output --&amp;gt; APPLE
    println(apple.toLowerCase()); // output --&amp;gt; apple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Stripping White Space :
&lt;/h2&gt;

&lt;p&gt;String values can often have white spaces in them, from beginning or in the end. Note : Space between the Characters are not white space. we can use &lt;code&gt;trim()&lt;/code&gt; function to remove them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String appleTrimmed = " apple ".trim();
    println(appleTrimmed) // output --&amp;gt; apple
    println(appleTrimmed.length()) // output --&amp;gt; 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Replace Character in String :
&lt;/h2&gt;

&lt;p&gt;If you want to replaces character from old char to new character.&lt;/p&gt;

&lt;p&gt;Note : Keep in mind replacing character is a string is not same process as setting character at some index in a string. Rule that Strings are immutable will also be applied there, thus when you try to replace a character you get a entire new string with replaced character.&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 plaintext"&gt;&lt;code&gt;    String apple = "apple";
    println(apple.replace("a","pinea")); // output --&amp;gt; pineapple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  String Concatenation using “+” operator
&lt;/h1&gt;

&lt;p&gt;We have already seen two ways to join two string, one is concat and other is join, but a very common pattern you will encounter you will see for concatenating two strings would be “+”. &lt;/p&gt;

&lt;p&gt;Using “+” operator works very same with concat function. Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String apple = "apple";
    String orange = "Orange";
    String berry = "StrawBerries";

    println(apple.concat(orange).concat(berry)); // output --&amp;gt; appleOrangeStrawBerries
    println(apple + orange + berry); // output --&amp;gt; appleOrangeStrawBerries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Which one should we use?
&lt;/h2&gt;

&lt;p&gt;In our opinion comparing between “concat()” and “+”, “+” operator seems more readable, but be careful using it with numeric type data. &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 plaintext"&gt;&lt;code&gt;    int orangeCount = 5;
    int berryCount = 5;
    println("fruits count:" + orangeCount + berryCount); 
    // wrong output --&amp;gt; fruits count:55

    println("fruits count:" + (orangeCount + berryCount)); 
    // right output --&amp;gt; fruits count:10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But as we suggested this as same issue as concat, since Strings are immutable we are basically creating new string better and faster way would be to use StringBuilder.&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating Format Strings
&lt;/h1&gt;

&lt;p&gt;We have covered lot of the core functionalities of the string, and we can clearly see a use-case in which we are appending strings with string, float, numbers etc… what if we can have placeholder values in string and on runtime these place holder could be replaced with values we want to put?&lt;/p&gt;

&lt;p&gt;This is what &lt;code&gt;String.format()&lt;/code&gt; function does. We create a string with placeholder/specifiers and we populate them with the value, we also call such type of string as template strings. &lt;/p&gt;

&lt;p&gt;We use different specifier for different type of data type, most commonly use once are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;%b for boolean,&lt;/li&gt;
&lt;li&gt;%s for Strings,&lt;/li&gt;
&lt;li&gt;%d for Integers only numbers&lt;/li&gt;
&lt;li&gt;%f for  floating point numbers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and others are there which you read more from here : &lt;a href="https://chetangupta.net/"&gt;https://chetangupta.net/&lt;/a&gt;&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;println(String.format("%s has %d apple, and %d oranges", "John Doe", 3, 2));
// output --&amp;gt; John Doe has 3 apple, and 2 oranges
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note : values are placed into the template position according to their occurrence in function parameter, &lt;/p&gt;

&lt;p&gt;Compare to concat or plus operator this method is useful when you are working with very long strings. Performance wise its not as great as StringBuilder cause it need to parse entire string and parameters before generating string. &lt;/p&gt;

&lt;h1&gt;
  
  
  Escape character in Strings
&lt;/h1&gt;

&lt;p&gt;While we are working with long string, if we try to break it into two parts most obvious thing which would come to your mind would be to press enter and continue with your string in next line, but if you try to do that compiler will treat you Syntax error, for instance :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String message = " 
        I want to make 
        very lengthy String!
    ";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To do these kind of functionality, you need to use special characters for &lt;code&gt;\n&lt;/code&gt; in the string for adding new line in the string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String message = "\nI want to make\nvery lengthy String!";
    /* 
    * Output :
    * I want to make
    * very lengthy String!
    */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Escaped Character :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\t → add horizontal tab 
\n → add new line
\’ → add single quotes in String
\” → add double quotes in String
\\ → add backslash in the String
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String message = "Hello\tWorld!";
    println(message); // output --&amp;gt; Hello  World!

    message = "Hello\nWorld!";
    println(message); 
    /*
    * Output --&amp;gt;
    *  Hello
    *  World!
    */

    message = "Hello\'World\'!";
    println(message); // output --&amp;gt; Hello'World'!

    message = "Hello\"World!\"";
    println(message); // output --&amp;gt; Hello"World!"

    message = "Hello\\World!\\";
    println(message); // output --&amp;gt; Hello\World!\
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Java Strings are Immutable
&lt;/h1&gt;

&lt;p&gt;If you read entire article thoroughly you have head us repeating this statement again and again. This is because its the main mechanism by which Java Strings function.  &lt;/p&gt;

&lt;p&gt;Key reason of having String as immutable is to have benefit of caching, performance and safety.&lt;/p&gt;

&lt;p&gt;String is the most widely used data structure in any program and  JVM optimizes the amount of memory allocated for them by storing only one copy of each String in the String pool. &lt;/p&gt;

&lt;p&gt;Thus caching the String literals and reusing them saves a lot of heap space because different String variables refer to the same object in the String pool saving crucial memory resource and improve performance of the application in general.&lt;/p&gt;

&lt;p&gt;One added advantage of String being immutable makes them thread-safe so Strings in concurrent environment are safe to read and update.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus : Riddle Solution
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   char thisIsA = 'A';
    String thisIsAlsoA = "A";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is &lt;code&gt;thisIsAlsoA&lt;/code&gt; is equal to &lt;code&gt;thisIsA&lt;/code&gt;? this was the riddle we asked.&lt;/p&gt;

&lt;p&gt;If you think Yes, then sorry mate! you are wrong. Conceptually you are right this should be correct but the issue is that Java is not dynamically typed language its a statically typed. Thus Types play major role here. Since type of String and char didn't match it failed. It wouldn’t  have failed in language like JavaScript. &lt;/p&gt;

&lt;p&gt;one more thing… String is collection of char right?, thus we can convert our String into Character Array using &lt;code&gt;toCharArray()&lt;/code&gt; ,  since Array is a collection thus justifying our statement programatically and if we compare first index position of the array with the character it would be equal. Nice !&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Lets have small recap :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We learned String is collection of sequence of Characters&lt;/li&gt;
&lt;li&gt;In Java we can create String in two ways - String literals and String Objects&lt;/li&gt;
&lt;li&gt;There are various operation that we can perform on strings - concat, length, compare and many more&lt;/li&gt;
&lt;li&gt;What are special escape characters in Strings&lt;/li&gt;
&lt;li&gt;Most importantly why String are Immutable! &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We hope you have learned a lot and untangled all the mysteries and doubts around Java String. Until next time happy hacking!&lt;/p&gt;

</description>
      <category>java</category>
      <category>kotlin</category>
      <category>android</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Confused over reverse, reversed, and asReveresed ? in Kotlin</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Thu, 21 Apr 2022 19:04:52 +0000</pubDate>
      <link>https://dev.to/ch8n/confused-over-reverse-reversed-and-asreveresed-in-kotlin-54ko</link>
      <guid>https://dev.to/ch8n/confused-over-reverse-reversed-and-asreveresed-in-kotlin-54ko</guid>
      <description>&lt;p&gt;Let’s solve a question and learn more about it.&lt;br&gt;
Originally post on &lt;code&gt;https://chetangupta.net/bbk8/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hi, I’m back with another question, and it’s very common and easy. You might have done this zillions of times.&lt;br&gt;
Question: Write a program to reverse an array or string :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nc"&gt;Example&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="nc"&gt;Input1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;Output&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it put yourself 👨🏻‍💻👇🏻:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/"&gt;https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well before we go into Kotlin’s standard library solution let’s look at ways to solve it manually :&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution 1: Taking Extra Space
&lt;/h2&gt;

&lt;p&gt;by taking extra space I mean we will use another list to reverse the list,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;input1&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;listOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverseExtraSpace&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// [2, 1, 5, 4]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverseExtraSpace&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mutableListOf&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;lastIndex&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastIndex&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastIndex&lt;/span&gt;&lt;span class="p"&gt;))&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;result&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Vola! with lots of code we are done reversing our array!&lt;br&gt;
Let’s analyze this approach and see the Pros and Cons :&lt;/p&gt;
&lt;h3&gt;
  
  
  Pros :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It’s an extension function — which means would only be visible on Receivers it’s assigned to, here Receiver is List and reverseExtraSpace function would be visible to this only. (we can make it more generalized using generics)&lt;/li&gt;
&lt;li&gt;The input list is not getting modified i.e. after reversing if we made changes in the original list it would be accidentally reflected into the reversed list.&lt;/li&gt;
&lt;li&gt;Mutations are scope in the body of the extension only, you get a read-only list from the return type.
All in all this code is very safe and sound.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Cons :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It has to iterate over the entire list.&lt;/li&gt;
&lt;li&gt;We take more space to store reversed list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…huh.. what do you mean this approach is not good? The interviewer will ask to optimize for space.&lt;/p&gt;

&lt;p&gt;Well when we are in an interview setting we have to show them our A-Game in terms of using your brain, but you need to explain to them as well writing code for correct and predictable behavior is much more important, than minor optimization. It should be the last part of your code evaluation metric unless it impacts the usability of the application.&lt;/p&gt;

&lt;p&gt;but in case he didn’t agree and insist on the better solution then …&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution 2 : Not Taking Extra Space
&lt;/h2&gt;

&lt;p&gt;So we will not create any array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;input1&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;listOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverseNoExtraSpace&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;// [2, 1, 5, 4]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverseNoExtraSpace&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toMutableList&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;mid&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastIndex&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;mid&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;firstIndex&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;lastIndex&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lastIndex&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;first&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;last&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;//swap&lt;/span&gt;
        &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and done! without using extra space.&lt;/p&gt;

&lt;p&gt;It’s very easy to mess up implementation and loss the Pros of Solution 1, remember its important to understand what kind of data you are sending as input, exposing as output and scope in which mutation should be allowed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Note in Kotlin that when we convert list to a Mutable list isn't a typecast, a new mutable list with the same items gets created. To remove that cost you need to take MutableList instead of List from the beginning.

Or you can use IntArray if you like.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution 3 : Using Standard Library Functions
&lt;/h2&gt;

&lt;p&gt;Now the nice part, by going through these solutions you already have know-how under the hood reverse operation works. In Kotlin standard library uses solution 2 as its base.&lt;br&gt;
On our List collection, we have two ways to reverse the order of the list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reversed — &lt;a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reversed.html"&gt;https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reversed.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;asReversed — &lt;a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-reversed.html"&gt;https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-reversed.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;both of them returns list in reversed order, but when you use reversed any changes done in original list is not reflected in reversed list. Thus make it safer to use it with mutable collections.&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 kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;list&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mutableListOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// mutable list&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;reversed&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;asReversed&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asReversed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1,2,3,4]&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [4,3,2,1]&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;asReversed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [4,3,2,1]&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1,9,3,4]&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [4,3,2,1]&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;asReversed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [4,3,9,1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note — If you are using List which is a read-only collection this issue isn’t there at all. because you can’t modify a List unless you convert it into a Mutable List, and even if you try to convert it would be an entirely new list, not the same list which you have reversed. So for List using reversed and asReversed is similar.&lt;br&gt;
but for a general rule, I will strongly recommend using reversed over asReversed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Bonus Part — Reverse
&lt;/h2&gt;

&lt;p&gt;Talking about Mutable-List, we have an additional reverse function — &lt;a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reverse.html"&gt;https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/reverse.html&lt;/a&gt;&lt;br&gt;
it Reverses elements in the list in place which means :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;input&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mutableListOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2, 3, 4, 5]&lt;/span&gt;
&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// retuns Unit not a list i.e. updates the exisiting list&lt;/span&gt;
&lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [5, 4, 3, 2, 1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;i.e. use it wisely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 💆🏻‍♀️
&lt;/h2&gt;

&lt;p&gt;That’s all folks! Hope this helps someone.&lt;br&gt;
Hope you find it informative and if you have any feedback or post request or want to subscribe to my mailing list forms are below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chetangupta.net/updates/"&gt;https://chetangupta.net/updates/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do consider Clap to show your appreciation, until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>java</category>
      <category>beginners</category>
    </item>
    <item>
      <title>BBK#6: Equal sides 🤝</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Wed, 20 Jan 2021 06:47:40 +0000</pubDate>
      <link>https://dev.to/ch8n/bbk-5-the-morse-code-5e3</link>
      <guid>https://dev.to/ch8n/bbk-5-the-morse-code-5e3</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in a Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn a lot!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;originally published on https://chetangupta.net/bbk7/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question:&lt;/code&gt; For a given array, find Index &lt;strong&gt;N&lt;/strong&gt; where the sum of integers to the left of &lt;strong&gt;N&lt;/strong&gt; is equal to the sum of integers to the right of &lt;strong&gt;N&lt;/strong&gt;, If there is no index that would make this return &lt;strong&gt;-1&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Example : 

for an array {1,2,3,4,3,2,1}
output would be 3 because at the 4th position of the array, 
the sum of left side of the index ({1,2,3}) and the sum of the right side of the index ({3,2,1}) both are equal to 6.

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

&lt;/div&gt;



&lt;p&gt;Try it put yourself :&lt;br&gt;
👨🏻‍💻👉 &lt;a href="https://www.codewars.com/kata/5679aa472b8f57fb8c000047/train/kotlin"&gt;Try Yourself&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Some Code Philosophy Ranting..
&lt;/h2&gt;

&lt;p&gt;I always categorize writing code into 3 levels.&lt;/p&gt;
&lt;h2&gt;
  
  
  Level 1 : Write for correctness
&lt;/h2&gt;

&lt;p&gt;You just go all in without minding best practices or patterns, just aim for the right output on all of your use-cases. The only optimisation I suggest to do here is to keep your code readable and write descriptive names or at-least comments.&lt;/p&gt;
&lt;h2&gt;
  
  
  Level 2 : Refactor to make it maintainable
&lt;/h2&gt;

&lt;p&gt;Once your code is working correctly, now is the time to make it maintainable, your aim is to preserve functionality, just update architecture, rename your variables, figure out ways to remove those comments and convert code into self expressive functions or variables. You DON'T change the functionality or algorithm used to solve the problem.&lt;/p&gt;
&lt;h2&gt;
  
  
  Level 3 : Optimize for memory and storage
&lt;/h2&gt;

&lt;p&gt;90% of your code wouldn’t be needing this step if you have mastered level 1 and 2. You will come to this step only when its critical to business or to your app performance. Micro optimization just ruins your code, not make it good. Anyways In this step your aim is to keep algorithm and architecture intact don’t change it. You have to change data structure or replace internals of your functions with code which return out the same result in better performance.  &lt;/p&gt;
&lt;h2&gt;
  
  
  Lets do it..
&lt;/h2&gt;

&lt;p&gt;Naive Algorithm to solve this would be&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compute sum from first n items lets call it as leftSum&lt;/li&gt;
&lt;li&gt;Compute sum remaining, i.e. n to last item of array, lets call it rightSum&lt;/li&gt;
&lt;li&gt;if both sums are equal print the index, else print -1&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Solution 1:
&lt;/h3&gt;

&lt;p&gt;Same old imperative way. 😪&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;findEvenIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;evenIndex&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="c1"&gt;// Loop max till the size of array&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;evenIndex&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// sum accumulator loop&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;loopCounter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

        &lt;span class="c1"&gt;// indicates sum from left side&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

        &lt;span class="c1"&gt;// indicates sum of remaining items&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;rightSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

        &lt;span class="c1"&gt;// loop till the end of list and compute left and write sums&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;when&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;loopCounter&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;evenIndex&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
                &lt;span class="n"&gt;loopCounter&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;evenIndex&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;leftSum&lt;/span&gt;&lt;span class="p"&gt;+=&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="n"&gt;rightSum&lt;/span&gt;&lt;span class="p"&gt;+=&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;rightSum&lt;/span&gt; &lt;span class="p"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;++&lt;/span&gt;&lt;span class="n"&gt;loopCounter&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// compare sum&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;rightSum&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// return found index&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;evenIndex&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// proceed for second round in loop&lt;/span&gt;
            &lt;span class="p"&gt;++&lt;/span&gt;&lt;span class="n"&gt;evenIndex&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// index not found&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n^2)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 2.48 ms on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an example how you don’t write the code, its fine when you are just getting started, but as your experience builds up, you need to make your code maintainable 👾.&lt;/p&gt;

&lt;p&gt;Even with the descriptive naming without comments I need to create mental a map of every step and track what this code does. Also the common accumulator pattern issue of mutability is applied here.&lt;/p&gt;

&lt;p&gt;Checkout why accumulator pattern in imperative style is bad.💡&lt;/p&gt;

&lt;h1&gt;
  
  
  checkout 👉  &lt;a href="https://chetangupta.net/reduce-fold/"&gt;Accumulator|Fold-Reduce&lt;/a&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Solution 2:
&lt;/h3&gt;

&lt;p&gt;We were using an accumulator to calculate the sum, instead of that why don’t we split the array into smaller chunks and find the sum?&lt;/p&gt;

&lt;p&gt;Let’s do that by using &lt;code&gt;Sublist()&lt;/code&gt;&lt;br&gt;
&lt;a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/sub-list.html"&gt;Sublist&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;findEvenIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;list&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toList&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;rightSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;rightSum&lt;/span&gt;&lt;span class="p"&gt;)&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;index&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 22.5 ms on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  SubList Ranting…
&lt;/h2&gt;

&lt;p&gt;If you are coming from Java background, subList is the function that comes to your mind when you want to split the array on particular index, but there is an inherit issue hidden in this function, let's understand that with example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;

  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;list&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mutableListOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// output : [1, 2, 3, 4, 5]&lt;/span&gt;

  &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;subs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// output : [1, 2, 3]&lt;/span&gt;

  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// output : [1, 2, 3, 4, 5]&lt;/span&gt;

  &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// output : [5, 2, 3]&lt;/span&gt;

  &lt;span class="nf"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;// output : [5, 2, 3, 4, 5]  &lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;You see its using the same list reference to show you value in your subList, this could lead to accidental mutations, let's see next solution which is an example of Level 3 and also fixes this issue.&lt;/p&gt;

&lt;p&gt;Solve many more 👇🏻&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://chetangupta.net/bbk-main/"&gt;Big-Brain-Kotlin&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Solution 3:&lt;br&gt;
Another function that is available in Kotlin Stdlib that can split your array is &lt;code&gt;Slice()&lt;/code&gt;&lt;br&gt;
&lt;a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/slice.html"&gt;Slice&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unlike sublist it doesn’t use the same reference to the List, it generates a new copy. We also have &lt;code&gt;sliceArray()&lt;/code&gt; which is specific to Arrays, instead of the List so we don’t have to covert our array to List and save one more computation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;findEvenIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IntArray&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;indices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sliceArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;rightSum&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sliceArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastIndex&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;leftSum&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;rightSum&lt;/span&gt;&lt;span class="p"&gt;)&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;index&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 2.48 ms on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice, We have optimized our code from ~22 ms to ~2 ms and achieved Level 3.&lt;/p&gt;

&lt;p&gt;There is one bonus way to solve it in more concise ways.&lt;br&gt;
for that you need to check out my personal site &lt;a href="https://chetangupta.net/bbk7/"&gt;BBK-7:Equal Sides 🤝&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;h1&gt;
  
  
  👥 Social
&lt;/h1&gt;

&lt;p&gt;Stalk Me 👀 : &lt;br&gt;&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>java</category>
      <category>android</category>
      <category>programming</category>
    </item>
    <item>
      <title>BBK#5: The Morse Code 🤫</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Tue, 29 Dec 2020 06:08:10 +0000</pubDate>
      <link>https://dev.to/ch8n/bbk-6-the-morse-code-4ppn</link>
      <guid>https://dev.to/ch8n/bbk-6-the-morse-code-4ppn</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in a Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn a lot!&lt;/p&gt;

&lt;p&gt;I have a secret code for you to crack detective! 🕵️‍♀️&lt;/p&gt;

&lt;p&gt;&lt;code&gt;originally published on https://chetangupta.net/bbk-main/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This quiz was suggested by Rohan Singh on Twitter, sorry for the delay mate!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question:&lt;/code&gt; You have received a secret message! unfortunately, you can't just read it, it is encoded in Morse code. Your task is to implement a function that would take the morse code as input and return a human-readable string. 3 spaces are used to separate words and&lt;br&gt;
Extra spaces before or after the code have no meaning and should be ignored.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;-.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; …&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.-&lt;/span&gt;&lt;span class="err"&gt; …&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.-&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt;… &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt;… &lt;/span&gt;&lt;span class="p"&gt;.-.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt; &lt;span class="p"&gt;-.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;-.&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.-.&lt;/span&gt; &lt;span class="p"&gt;-.-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;.-&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;-.&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;morseCode&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"-.-- --- ..-   .... .- ...- .   .-   -... .. --.   -... .-. .- .. -.   ..-. --- .-.   -.- --- - .-.. .. -."&lt;/span&gt;  
&lt;span class="c1"&gt;// write a function that converts this MorseCode to English fun decodeMorse(morseCode:String):String{   &lt;/span&gt;
 &lt;span class="c1"&gt;// .. do stuff &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Given Morse Code Decoder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;morseDecoder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;
        &lt;span class="s"&gt;".-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-..."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"C"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"D"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"E"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"..-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"F"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"G"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"...."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"H"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"I"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".---"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"J"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"K"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".-.."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"L"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"M"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"N"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"---"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"O"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".--."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"P"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--.-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"Q"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"R"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"..."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"S"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"T"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"..-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"U"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"...-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"V"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"W"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-..-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"X"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"Y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--.."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".----"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"..---"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"...--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"....-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"....."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-...."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--..."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"---.."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"----."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"9"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-----"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".-.-.-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"--..--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;","&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"---..."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"..--.."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.-.--"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"...---..."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"SOS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-....-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"''"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-..-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-.--.-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"()"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;".--.-."&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"@"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"-...-"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s"&gt;"="&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it put yourself :&lt;br&gt;
👨🏻‍💻👉 &lt;a href="https://www.codewars.com/kata/54b724efac3d5402db00065e/train/kotlin"&gt;Try Yourself&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Solution 1:
&lt;/h1&gt;

&lt;p&gt;Same old imperative way. 😪&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;decodeMorse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;morseWords&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"   "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;humanized&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StringBuilder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;morseWord&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;morseWords&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;morseChars&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;morseWord&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;morseChar&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;morseChars&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;morseChar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNotEmpty&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;humanized&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;morseDecoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;morseChar&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;humanized&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&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;humanized&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n^2)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 509.0 us on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Btw there is nothing wrong in this way, just the loops make it very expressive, there is no issue of mutations and accidental updates in it. 🙌🏻&lt;/p&gt;

&lt;p&gt;Checkout why accumulator pattern in imperative style is bad.💡&lt;/p&gt;

&lt;h1&gt;
  
  
  checkout 👉  &lt;a href="https://chetangupta.net/reduce-fold/"&gt;Accumulator|Fold-Reduce&lt;/a&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Solution 2:
&lt;/h1&gt;

&lt;p&gt;Imperative equivalent code in functional style | Stdlib function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;decodeMorse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;String&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;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"   "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joinToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;separator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;letter&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;morseDecoder&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joinToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;separator&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n^2)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 639.0 us on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The performance hit of there is due to joinToString operation one at the outer loop and multiple times into the inner loop, not good! dood (dude)...☹️&lt;/p&gt;

&lt;p&gt;learn joinToString and it's advanced use cases 💡&lt;/p&gt;

&lt;h1&gt;
  
  
  checkout 👉 &lt;a href="https://chetangupta.net/list-to-string/"&gt;list-to-string&lt;/a&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Solution 3:
&lt;/h1&gt;

&lt;p&gt;What if we call it once? , if we eliminate the nesting, i.e flatten our words to char?&lt;/p&gt;

&lt;p&gt;👨🏻‍💻 Let's flatten our List using FlatMap&lt;/p&gt;

&lt;p&gt;flatMap&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;decodeMorse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"  "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flatMap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;morseDecoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joinToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 464.0 us us on my machine&lt;/span&gt;
&lt;span class="nc"&gt;Whola&lt;/span&gt;&lt;span class="p"&gt;!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Solution 4:
&lt;/h1&gt;

&lt;p&gt;Or Change the way you are solving this problem 💁‍♀️&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;decodeMorse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;String&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;code&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"  "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;morseDecoder&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joinToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// 👨🏻‍🔧 complexity : O(n)&lt;/span&gt;
&lt;span class="c1"&gt;// ⏱ performance : took 441.0 us on my machine&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't get attached to a solution!&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;The aim of these articles is not hated on Java, but to help people learn various ways in which they can write the same logic better and more Kotlin standard library-focused way.&lt;br&gt;
Hope you find it informative and if you have any feedback or post request or want to subscribe to my mailing list forms are below.&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Solve many more 👇🏻&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://chetangupta.net/bbk-main/"&gt;Big-Brain-Kotlin&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>programming</category>
      <category>java</category>
    </item>
    <item>
      <title>Data Structures in Kotlin | Linked-List</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Wed, 23 Dec 2020 04:02:04 +0000</pubDate>
      <link>https://dev.to/ch8n/data-structures-in-kotlin-linked-list-34fb</link>
      <guid>https://dev.to/ch8n/data-structures-in-kotlin-linked-list-34fb</guid>
      <description>&lt;p&gt;Hola Amigos! 🙌, I do tech blogging at &lt;a href="https://chetangupta.net/"&gt;AndroidBites&lt;/a&gt;, do check it out.&lt;/p&gt;

&lt;p&gt;This page is dedicated to my learning of DataStructure. I never took time to learn them up and always been scared of them, but actual growth comes from fighting your fears, so I have decided to create my own version of them and entirely in Kotlin.&lt;br&gt;
So my aim is to :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create my own data structure implementations&lt;/li&gt;
&lt;li&gt;provide them with the behavior as close the standard library&lt;/li&gt;
&lt;li&gt;Battle-tested and Entirely in Kotlin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I believe in sharing so if you like to share too your always invited to contribute! 🤩&lt;br&gt;
Let's grow together 💪🏻 ! happy hacking 💻. &lt;br&gt;
P.S : Don't forget to show love and support 🥰 by sharing! &amp;amp; providing feedback! 📝 and PRs are always welcome&lt;/p&gt;

&lt;p&gt;Chao!&lt;/p&gt;
&lt;h1&gt;
  
  
  📖 Repository
&lt;/h1&gt;
&lt;h2&gt;
  
  
  &lt;a href="https://github.com/ch8n/DataStructure-in-Kotlin"&gt;DataStructure-in-Kotlin&lt;/a&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  ⏰ MileStones
&lt;/h1&gt;
&lt;h2&gt;
  
  
  &lt;a href="(https://github.com/ch8n/DataStructure-in-Kotlin)"&gt;Linked-List 1 : Create| Read | Update | Delete&lt;/a&gt;
&lt;/h2&gt;
&lt;h1&gt;
  
  
  👥 Social
&lt;/h1&gt;

&lt;p&gt;Stalk Me 👀 : &lt;br&gt;&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;© License&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Copyright [2020] [Chetan gupta] [chetangupta.net]
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at&lt;span class="sb"&gt;

     http://www.apache.org/licenses/LICENSE-2.0

&lt;/span&gt;   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>kotlin</category>
      <category>android</category>
      <category>datastructures</category>
      <category>programming</category>
    </item>
    <item>
      <title>AndroidBites | Deepest Dive into View-Binding</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Sun, 06 Dec 2020 09:46:45 +0000</pubDate>
      <link>https://dev.to/ch8n/androidbites-deepest-dive-into-view-binding-bjp</link>
      <guid>https://dev.to/ch8n/androidbites-deepest-dive-into-view-binding-bjp</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ybbiFxiI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1607247391188/jSKqJtH5F.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ybbiFxiI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1607247391188/jSKqJtH5F.png" alt="carbon (6) (1).png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm pretty late to the party but here is my blog on view-binding, &lt;br&gt;
It's pretty much more in-depth than others you would find in the community.&lt;/p&gt;

&lt;h1&gt;
  
  
  Glossary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Is data binding not working in all the modules? Why your fields are not getting generated?&lt;/li&gt;
&lt;li&gt;How to view the source code of your generated binding classes?&lt;/li&gt;
&lt;li&gt;Generated classes are Kotlin or Java? and why?&lt;/li&gt;
&lt;li&gt;Do View-binding views are never null?&lt;/li&gt;
&lt;li&gt;How to access included views?  and  tags?&lt;/li&gt;
&lt;li&gt;How to bind Activities, Fragments, Adapters, and CustomViews?&lt;/li&gt;
&lt;li&gt;When to use bind and Inflate?&lt;/li&gt;
&lt;li&gt;Controlling ViewBinding Generation?&lt;/li&gt;
&lt;li&gt;Reducing boilerplate code with Delegates and Base-Class for ViewBinding in Activity and Fragments?&lt;/li&gt;
&lt;li&gt;Common mistakes and Anti-patterns in ViewBinding?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/viewbinding/"&gt;AndroidBites | View-Binding&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 : &lt;br&gt;&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>BigBrainKotlin#4 | Among Us</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Mon, 30 Nov 2020 08:19:22 +0000</pubDate>
      <link>https://dev.to/ch8n/bigbrainkotlin-4-among-us-37hi</link>
      <guid>https://dev.to/ch8n/bigbrainkotlin-4-among-us-37hi</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn alot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1VlKqwJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w3whhvj3pqicr29fn8wj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1VlKqwJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w3whhvj3pqicr29fn8wj.jpg" alt="BBK Special"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The aim of these articles is not hate on Java, but to help people learn various ways in which they can write the same logic better and more Kotlin standard library focused way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question&lt;/code&gt;: &lt;br&gt;
Find the imposter from the given array with at least 3 items, it's either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "Imposter" N...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;imposter(arrayOf(2,6,8,-10,3)) =&amp;gt; returns 3

imposter(arrayOf(206847684,1056521,7,17,1901,21104421,7,1,35521,1,7781)) =&amp;gt; returns 206847684

imposter(arrayOf(Integer.MAX_VALUE, 0, 1))=&amp;gt; returns 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it out yourself, or submit it in the comments before checking out my solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/bbk5/"&gt;BigBrainKotlin#4&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 :&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
    </item>
    <item>
      <title>BigBrainKotlin#3 | Spin My Words...</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Mon, 30 Nov 2020 08:15:54 +0000</pubDate>
      <link>https://dev.to/ch8n/bigbrainkotlin-3-spin-my-words-56h9</link>
      <guid>https://dev.to/ch8n/bigbrainkotlin-3-spin-my-words-56h9</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn alot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" alt="BBK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The aim of these articles is not hate on Java, but to help people learn various ways in which they can write the same logic better and more Kotlin standard library focused way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question&lt;/code&gt;: &lt;br&gt;
Write a function that reversed all words in the String whose length is five or more letter words reversed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spinWords( "Hey fellow warriors" ) =&amp;gt; returns "Hey wollef sroirraw" 
spinWords( "This is a test") =&amp;gt; returns "This is a test" 
spinWords( "This is another test" )=&amp;gt; returns "This is rehtona test"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it out yourself, or submit it in the comments before checking out my solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/bbk4/"&gt;BigBrainKotlin#3&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 :&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>algorithms</category>
      <category>java</category>
      <category>android</category>
    </item>
    <item>
      <title>BigBrainKotlin#2 | Mumbling...</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Mon, 30 Nov 2020 08:13:18 +0000</pubDate>
      <link>https://dev.to/ch8n/bigbrainkotlin-2-mumbling-39kj</link>
      <guid>https://dev.to/ch8n/bigbrainkotlin-2-mumbling-39kj</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn alot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" alt="BBK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The aim of these articles is not hate on Java, but to help people learn various ways in which they can write the same logic better and more Kotlin standard library focused way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question&lt;/code&gt;: &lt;br&gt;
This time no story, no theory. The examples below show you how to do :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mummble("abcd") -&amp;gt; "A-Bb-Ccc-Dddd"
mummble("RqaEzty") -&amp;gt; "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
mummble("cwAt") -&amp;gt; "C-Ww-Aaa-Tttt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it out yourself, or submit it in the comments before checking out my solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/bbk3/"&gt;BigBrainKotlin#2&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 :&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>java</category>
      <category>algorithms</category>
      <category>android</category>
    </item>
    <item>
      <title>BigBrainKotlin#1 | Find Max and Min</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Mon, 30 Nov 2020 08:09:47 +0000</pubDate>
      <link>https://dev.to/ch8n/bigbrainkotlin-1-find-max-and-min-9db</link>
      <guid>https://dev.to/ch8n/bigbrainkotlin-1-find-max-and-min-9db</guid>
      <description>&lt;p&gt;Don't be a Java-ish dev in Kotlin-ish world, improve your knowledge about Koltin Standard Library and write better Kotlin code. ✌🏻 If your Java dev migrating to Kotlin this will help you learn alot!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Yr2nSML--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e5p16z6mlksi1qmn430k.jpg" alt="BBK"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The aim of these articles is not hate on Java, but to help people learn various ways in which they can write the same logic better and more Kotlin standard library focused way.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Question&lt;/code&gt;: &lt;br&gt;
Print the Highest and Lowest number from the input string. &lt;br&gt;
&lt;code&gt;8 3 -5 42 -1 0 0 -9 4 7 4 -4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Try it out yourself, or submit it in the comments before checking out my solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/bbk2/"&gt;BigBrainKotlin#1&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 :&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>algorithms</category>
      <category>java</category>
      <category>android</category>
    </item>
    <item>
      <title>Implement LRU Caching into your Repository | Androidbites </title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Mon, 07 Sep 2020 04:48:33 +0000</pubDate>
      <link>https://dev.to/ch8n/androidbites-implement-lru-caching-into-your-repository-5e4i</link>
      <guid>https://dev.to/ch8n/androidbites-implement-lru-caching-into-your-repository-5e4i</guid>
      <description>&lt;p&gt;Hi Devs, Repository pattern is available in almost every codebase, people often design it pretty well but often miss out on the caching behavior from It and rely on retrofit caching or Live data for caching data or put on some hack in the android lifecycle to only get data once to save APIs calls.&lt;/p&gt;

&lt;p&gt;follow up the following article and learn how to implement LRU cache in your repository in 5 easy steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6-kCgKP4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/srrdbv6racueartnmfn4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6-kCgKP4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/srrdbv6racueartnmfn4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  👉 &lt;a href="https://chetangupta.net/cache-repository"&gt;AndroidBites|cache-repository&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Hope to see you on the other side...&lt;/p&gt;

&lt;p&gt;Until next time. Happy Hacking! 👩‍💻&lt;/p&gt;

&lt;p&gt;Stalk Me 👀 :&lt;br&gt;
&lt;a href="https://bit.ly/ch8n-linkdIn"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-medium-blog"&gt;Medium&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-twitter"&gt;Twitter&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-stackOflow"&gt;StackOverflow&lt;/a&gt; | &lt;a href="https://bit.ly/ch8n-codewar"&gt;CodeWars&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-home"&gt;WorkX&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-git"&gt;Github&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-insta"&gt;Instagram&lt;/a&gt; |&lt;a href="https://bit.ly/ch8n-youtube"&gt;Youtube&lt;/a&gt; &lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>java</category>
      <category>android</category>
      <category>androidbites</category>
    </item>
    <item>
      <title>3 List To String Tips You probably didn't know</title>
      <dc:creator>Chetan garg</dc:creator>
      <pubDate>Sun, 23 Aug 2020 18:01:18 +0000</pubDate>
      <link>https://dev.to/ch8n/3-list-to-string-tips-you-probably-didn-t-know-4m23</link>
      <guid>https://dev.to/ch8n/3-list-to-string-tips-you-probably-didn-t-know-4m23</guid>
      <description>&lt;p&gt;Hi #androidDevs, This is Androidbites where I try to break down a small concept into an understandable code snippet and share my learning experience with it.&lt;/p&gt;

&lt;p&gt;String to List conversions and back to it i.e List to String are very much crucial operations need to know if you're into competitive programming. Today let's explore how to do that in Kotlin...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zlPjyRSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n4en7ay8ijvwlrz3ru6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zlPjyRSk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n4en7ay8ijvwlrz3ru6d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to learn more advance operations that can be performed on the &lt;code&gt;joinToString()&lt;/code&gt; follow up from:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chetangupta.net/list-to-string/"&gt;https://chetangupta.net/list-to-string/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;see you on the other side 😈&lt;/p&gt;

&lt;p&gt;Happy Hacking!&lt;/p&gt;

&lt;p&gt;Follow me: LinkedIn : bit.ly/ch8n-linkdIn Medium : bit.ly/ch8n-medium Twitter: bit.ly/ch8n-twitter StackOverflow : bit.ly/ch8n-stackOflow CodeWars : bit.ly/ch8n-codewar Portfolio : bit.ly/ch8n-home Github : bit.ly/ch8n-git Instagram : bit.ly/ch8n-insta Youtube: bit.ly/ch8n-youtube&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
      <category>java</category>
      <category>androidbites</category>
    </item>
  </channel>
</rss>
