Thursday, 31 March 2016

Java Tutorial : Java String Concatenation


Click here to watch in Youtube :
https://www.youtube.com/watch?v=Fc0C-ZrmSTE&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java String Concatenation 
ConcatenationDemo1.java
public class ConcatenationDemo1
{

    public static void main(String[] args)
    {
        /*
         * String concatenation operator produces a new
         * string by appending the second operand onto the
         * end of the first operand.
         */
        String string1 = "Hello" + " World";
        System.out.println(string1);// Hello World

        /*
         * The string concatenation operator can concat not
         * only string but primitive values also.
         */
        String string2 = 50 + 30 + "Hello" + 40 + 40;
        System.out.println(string2);// 80Sachin4040

    }
}
Output
Hello World
80Hello4040
ConcatenationDemo2.java
public class ConcatenationDemo2
{

    public static void main(String[] args)
    {
        String s1 = "Sachin ";  
        String s2 = "Tendulkar";
        String s3 = s1.concat(s2);
        System.out.println(s3);// Sachin Tendulkar

    }

}
Output
Sachin Tendulkar
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_Concatination_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_Concatination_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_Concatination_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String Comparison


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=IYWyfrivZYg&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String Comparison 
    CompareByEqualsDemo.java
    public class CompareByEqualsDemo
    {
    
        public static void main(String[] args)
        {
            String s1 = "Peter";
            String s2 = "Peter";
            String s3 = new String("Peter");
            String s4 = "Dave";
            System.out.println(s1.equals(s2));// true
            System.out.println(s1.equals(s3));// true
            System.out.println(s1.equals(s4));// false
        }
    
    }
    
    Output
    true
    true
    false
    
    CompareByEqualsIgnoreCaseDemo.java
    public class CompareByEqualsIgnoreCaseDemo
    {
    
        public static void main(String[] args)
        {
            String s1 = "peter";
            String s2 = "PETER";
    
            System.out.println(s1.equals(s2));// false
            System.out.println(s1.equalsIgnoreCase(s2));// true
    
        }
    
    }
    
    Output
    false
    true
    
    CompareByDemo.java
    public class CompareByDemo
    {
    
        public static void main(String[] args)
        {
            String s1 = "Peter";
            String s2 = "Peter";
            String s3 = new String("Peter");
    
            /*
             * true (because both refer to same instance)
             */
            System.out.println(s1 == s2);
    
            /*
             * false(because s3 refers to instance created in
             * nonpool)
             */
            System.out.println(s1 == s3);
    
        }
    
    }
    
    Output
    true
    false
    
    CompareByCompareToDemo.java
    public class CompareByCompareToDemo
    {
    
        public static void main(String[] args)
        {
            String s1 = "Sachin";
            String s2 = "Sachin";
            String s3 = "Ratan";
            
            System.out.println(s1.compareTo(s2));// 0
    
            /*
             * 1(because s1>s3)
             */
            System.out.println(s1.compareTo(s3));
            /*
             * -1(because s3 < s1 )
             */
            System.out.println(s3.compareTo(s1));
    
        }
    
    }
    
    Output
    0
    1
    -1
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_Comparison_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_Comparison_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_Comparison_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [codePointCount(int beginIndex,int endIndex) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=pb2rT6r69m4&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [codePointCount(int beginIndex,int endIndex) method] 
    CodePointCountDemo.java
    /*
     * public int codePointCount(int beginIndex, int
     *                                      endIndex)
     * 
     * Parameters: 
     * ---------- 
     * beginIndex - the index to the first char of the text
     * range. 
     * 
     * endIndex - the index after the last char of
     * the text range.
     * 
     * Returns: 
     * ------- 
     * the number of Unicode code points in the specified
     * text range
     * 
     * Throws: 
     * ------ 
     * IndexOutOfBoundsException - if the beginIndex is
     * negative, or endIndex is larger than the length of
     * this String, or beginIndex is larger than endIndex.
     */
    
    public class CodePointCountDemo
    {
    
        public static void main(String[] args)
        {
            String str = "JAVA programming language";
            System.out.println("String = " + str);
    
            int retval = str.codePointCount(1, 8);
    
            System.out.println("Codepoint count = " + retval);
    
        }
    
    }
    
    Output
    String = JAVA programming language
    Codepoint count = 7
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_codePointCount_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_codePointCount_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_codePointCount_App/?at=master

    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [codePointBefore(int index) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=LF7lxdGbKis&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [codePointBefore(int index) method]
    CodePointBeforeDemo.java
    /*
     * public int codePointBefore(int index)
     * 
     * Parameters: 
     * ---------- 
     * index - the index following the code point that
     * should be returned
     * 
     * Returns: 
     * ------- 
     * the Unicode code point value before the given index.
     * 
     * Throws: 
     * ------ 
     * IndexOutOfBoundsException - if the index argument is
     * less than 1 or greater than the length of this
     * string.
     */
    public class CodePointBeforeDemo
    {
    
        public static void main(String[] args)
        {
            String str = "JAVA";
            System.out.println("String = " + str);
    
            // codepoint before index 1 i.e J
            int retval = str.codePointBefore(1);
    
            // prints character before index1 in string
            System.out.println("Character(unicode point) = " + retval);
    
        }
    
    }
    
    Output
    String = JAVA
    Character(unicode point) = 74
    
    
    
    Refer: 
    https://en.wikipedia.org/wiki/List_of_Unicode_characters
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_codePointBefore_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_codePointBefore_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_codePointBefore_App/?at=master
    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [codePointAt(int index) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=og707Rf1eD8&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [codePointAt(int index) method] 
    CodePointAtDemo.java
    /*
     * public int codePointAt(int index)
     * 
     * Parameters: 
     * ---------- 
     * index - the index to the char values
     * 
     * Returns: 
     * ------- 
     * the code point value of the character at the index
     * 
     * Throws: 
     * ------ 
     * IndexOutOfBoundsException - if the index argument is
     * negative or not less than the length of this string.
     */
    
    public class CodePointAtDemo
    {
    
        public static void main(String[] args)
        {
            String str = "JAVA";
            System.out.println("String = " + str);
    
            int retval = str.codePointAt(1);
            System.out.println("Character(unicode point) = " + retval);
            
        }
    
    }
    
    Output
    String = JAVA
    Character(unicode point) = 65
    
    Refer: 
    https://en.wikipedia.org/wiki/List_of_Unicode_characters
    C lick the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_codePointAt_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_codePointAt_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_codePointAt_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [copyValueOf(char[] data,int offset,int count) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=lrButyBBUCs&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [copyValueOf(char[] data,int offset,int count) method] 
    CopyValueOfDemo.java
    /*
     * public static String copyValueOf(char[] data, 
     *                           int offset, int count) 
     * 
     * Equivalent to valueOf(char[], int, int).
     * 
     * Parameters: 
     * ---------- 
     * data - the character array. 
     * 
     * offset - initial offset of the subarray. 
     * 
     * count - length of the subarray.
     * 
     * Returns: 
     * ------- 
     * a String that contains the characters of the
     * specified subarray of the character array.
     * 
     * Throws: 
     * ------ 
     * IndexOutOfBoundsException - if offset is negative, or
     * count is negative, or offset+count is larger than
     * data.length.
     */
    
    public class CopyValueOfDemo
    {
    
        public static void main(String[] args)
        {
            char[] charArray =
            { 'H', 'i', ' ', 'W', 'e', 'l', 'c', 'o', 'm', 'e' };
    
            String str = String.copyValueOf(charArray, 6, 3);
            System.out.println(str);
    
        }
    
    }
    
    Output
    com
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_copyValueOf_Offset_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_copyValueOf_Offset_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_copyValueOf_Offset_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [copyValueOf(char[] data) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=09ZMmsqvvaw&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [copyValueOf(char[] data) method] 
    CopyValueOfDemo.java
    /*
     * public static String copyValueOf(char[] data)
     * 
     * Equivalent to valueOf(char[]).
     * 
     * Parameters: 
     * ---------- 
     * data - the character array.
     * 
     * Returns: 
     * -------  
     * a String that contains the
     * characters of the character array.
     */
    public class CopyValueOfDemo
    {
    
        public static void main(String[] args)
        {
            char[] charArray =
            { 'H', 'i' };
    
            String str = String.copyValueOf(charArray);
            System.out.println(str);
    
        }
    
    }
    
    Output
    Hi
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_copyValueOf_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_copyValueOf_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_copyValueOf_App/?at=master
    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [contentEquals(StringBuffer sb) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=4t2JhuF_ER8&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [contentEquals(StringBuffer sb) method] 
    ContentEqualsDemo.java
    /*
     * public boolean contentEquals(StringBuffer sb)
     * 
     * Parameters: 
     * ---------- 
     * sb - The StringBuffer to compare this String against
     * 
     * Returns: 
     * ------- 
     * true if this String represents the same sequence of
     * characters as the specified StringBuffer, false
     * otherwise
     */
    public class ContentEqualsDemo
    {
    
        public static void main(String[] args)
        {
            String str = "Welcome Peter";
            StringBuffer sb1 = new StringBuffer("Welcome Peter");
            StringBuffer sb2 = new StringBuffer("Hello");
    
            boolean result = str.contentEquals(sb1);
            System.out.println("str.contentEquals(sb1) = " + result);
            result = str.contentEquals(sb2);
            System.out.println("str.contentEquals(sb2) = " + result);
    
        }
    
    }
    
    Output
    str.contentEquals(sb1) = true
    str.contentEquals(sb2) = false
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_contentEquals_sb_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_contentEquals_sb_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/12836b6e32056aa84ee5263036ba2429cc0bd845/BasicJava/StringDemo_contentEquals_sb_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Wednesday, 30 March 2016

    Java Tutorial : Java String [contentEquals(CharSequence cs) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=NMG2oFYXbGc&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [contentEquals(CharSequence cs) method] 
    ContentEqualsDemo.java
    /*
     * public boolean contentEquals(CharSequence cs)
     * 
     * Parameters: 
     * ---------- 
     * cs - The sequence to compare this String against
     * 
     * Returns: 
     * ------- 
     * true if this String represents the same sequence of
     * char values as the specified sequence, false
     * otherwise
     */
    
    public class ContentEqualsDemo
    {
    
        public static void main(String[] args)
        {
            String str1 = "Welcome Peter";
            String str2 = "Hi";
            String str3 = "Welcome Peter";
    
            boolean result = str1.contentEquals(str2);
            System.out.println("\"Welcome Peter\".contentEquals(\"Hi\") = " + result);
            result = str1.contentEquals(str3);
            System.out.println("\"Welcome Peter\".contentEquals(\"Welcome Peter\") = " + result);
    
        }
    
    }
    
    Output
    "Welcome Peter".contentEquals("Hi") = false
    "Welcome Peter".contentEquals("Welcome Peter") = true
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_contentEquals_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_contentEquals_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_contentEquals_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [valueOf methods]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=DfX43K-iD1I&list=UUhwKlOVR041tngjerWxVccw

     Click the below Image to Enlarge
    Java Tutorial : Java String [valueOf methods] 

    ValueOfDemo.java
    public class ValueOfDemo
    {
    
        public static void main(String[] args)
        {
            int intValue=30;  
            String str=String.valueOf(intValue);
            System.out.println(str);
            
            double doubleValue=30;  
            str=String.valueOf(doubleValue);
            System.out.println(str);
            
            char[] charArray ={'H','i'};;
            str=String.valueOf(charArray);
            System.out.println(str);
            
            boolean value = true;
            str=String.valueOf(value);
            System.out.println(str);        
        }
    
    }
    
    Output
    30
    30.0
    Hi
    true
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_valueOf_methods_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_valueOf_methods_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_valueOf_methods_App/?at=master

    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [toCharArray() method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=WSC-AXsho9E&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [toCharArray() method] 
    ToCharArrayDemo.java
    /*
     * public char[] toCharArray()
     * 
     * 
     * Returns: 
     * --------
     * 
     * a newly allocated character array whose length is the
     * length of this string and whose contents are
     * initialized to contain the character sequence
     * represented by this string.
     */
    public class ToCharArrayDemo
    {
    
        public static void main(String[] args)
        {
            String str = "Welcome";
            char[] charArray = str.toCharArray();
            for (char c : charArray)
            {
                System.out.println(c);
            }
        }
    
    }
    
    Output
    W
    e
    l
    c
    o
    m
    e
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_toCharArray_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_toCharArray_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_toCharArray_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [join method-Iterable]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=g42wdErMKXs&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [join method-Iterable] 
    JoinDemo.java
    import java.util.LinkedHashSet;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Set;
    
    /*
     * public static String join(CharSequence delimiter,
     *              Iterable<? extends CharSequence> elements)
     * 
     * Parameters: 
     * ----------- 
     * delimiter - a sequence of characters that is used
     * to separate each of the elements in the resulting
     * String 
     * 
     * elements - an Iterable that will have its
     * elements joined together.
     * 
     * Returns: 
     * -------- 
     * a new String that is composed from the elements
     * argument
     * 
     * Throws: 
     * ------- 
     * NullPointerException - If delimiter or elements
     * is null
     */
    
    public class JoinDemo
    {
        public static void main(String[] args)
        {
            List<String> listOfStrings = new LinkedList<>();
            listOfStrings.add("Java");
            listOfStrings.add("is");
            listOfStrings.add("cool");
    
            // message returned is: "Java|is|cool"
            String message = String.join("|", listOfStrings);
            System.out.println(message);
    
            Set<String> setOfStrings = new LinkedHashSet<>();
            setOfStrings.add("Java");
            setOfStrings.add("is");
            setOfStrings.add("very");
            setOfStrings.add("cool");
    
            // message returned is: "Java-is-very-cool"
            message = String.join("-", setOfStrings);
            System.out.println(message);
        }
    
    }
    
    Output
    Java|is|cool
    Java-is-very-cool
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_Join_Iterable_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_Join_Iterable_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_Join_Iterable_App/?at=master

    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [join(CharSequence delimiter,CharSequence... elements) method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=vjUPeAaUV1k&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [join(CharSequence delimiter,CharSequence... elements) method] 
    JoinDemo.java
    /*
     * public static String join(CharSequence delimiter,
     *                              CharSequence... elements)
     * 
     * Parameters: 
     * ----------- 
     * delimiter - the delimiter that separates each element
     * 
     * elements - the elements to join together.
     * 
     * Returns: 
     * -------- 
     * a new String that is composed of the elements
     * separated by the delimiter.
     * 
     * Throws: 
     * ------- 
     * NullPointerException - If delimiter or elements is
     * null
     */
    
    public class JoinDemo
    {
        public static void main(String[] args)
        {
            String str1 = "welcome";
            String str2 = "to";
            String str3 = "India";
    
            String joinString = String.join("_", str1, str2, str3);
            System.out.println("JoinString = " + joinString);
    
        }
    
    }
    
    Output
    JoinString = welcome_to_India
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_join_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_join_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_join_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Java Tutorial : Java String [intern() method]


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=vx2iB6ahAYE&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial : Java String [intern() method] 
    InternDemo.java
    /*
     * public String intern()
     *  
     * Returns: 
     * -------
     * a string that has the same contents as 
     * this string, but is guaranteed to be 
     * from a pool of unique strings.
     */
    public class InternDemo
    {
        public static void main(String[] args)
        {
            String s1 = new String("hello");
            String s2 = "hello";
    
            /*
             * returns string from pool, now it will be same as
             * s2
             */
    
            String s3 = s1.intern();
            System.out.println(s3);
    
            /*
             * false because reference is different
             */
            System.out.println(s1 == s2);
    
            /*
             * true because reference is same
             */
            System.out.println(s2 == s3);
    
        }
    }
    
    Output
    hello
    false
    true
    
    Click the below link to download the code:
    https://sites.google.com/site/javaee4321/java/StringDemo_intern_App.zip?attredirects=0&d=1

    Github Link:
    https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_intern_App

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/89dfdef018d2970576505c9f498b5e4f28628c35/BasicJava/StringDemo_intern_App/?at=master

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial