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] |
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); } }
Java|is|cool Java-is-very-cool
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:
No comments:
Post a Comment