Wednesday, 30 March 2016

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
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge