package test; import java.util.Arrays; import java.util.List; import java.util.StringJoiner; /** * Java program ADVERTISEMENT to show how to join String in Java 8. * There are two ways to do that in Java 8, by using StringJoiner or * by using join() method of String class. * @author Javin */ public class Test { public static void main(String args[]) { // StringJoiner can join multiple String using any delimiter // Let's create a CSV String by joining Stirng using comma StringJoiner joiner = new StringJoiner(","); joiner.add("one"); joiner.add("two"); joiner.add("three"); System.out.println("Comma separated String : " + joiner.toString()); // You can combine all three lines into one because // StringJoiner provides a fluent interface StringJoiner delimitedString = new StringJoiner("|").add("id").add("name"); System.out.println("Pipe delimited String : " + delimitedString); // 2nd Example: You can also join String by String.join() method // By far, this is the most convenient method to join Strings // in Java. String csv = String.join(":", "abc", "bcd", "def"); System.out.println("colon separated String : " + csv); // You can even use String.join() method to join contents of // ArrayList, Array, LinkedList or any collection, actually // any container which implements Iterable interface List mylist = Arrays.asList("London", "Paris", "NewYork"); String joined = String.join("||", mylist); System.out.println("Joined String : " + joined); } } Output Comma separated String : one,two,three Pipe delimited String : id|name colon separated String : abc:bcd:def Joined String : London||Paris||NewYork
相关推荐
Offering a gentle introduction to the field, assuming no prior knowledge of the subject, Java in Two Semesters is the ideal companion to undergraduate modules in software development or programming.
@param [in] T the value type is transformed to string @param [in] RefT the value reference to translate @param [in] split split mark between two element if have @return formated string */ template...
8 Kth Largest Element in an Array 35 9 Wildcard Matching 37 10 Regular Expression Matching in Java 39 11 Merge Intervals 43 12 Insert Interval 45 13 Two Sum 47 14 Two Sum II Input array is sorted 49 ...
### Java的String用法类型总结 #### 一、概述 在Java编程语言中,`String` 类是最常用的数据类型之一,用于表示不可变的字符序列。由于字符串在实际开发中的重要性和高频使用特性,深入理解并掌握其用法至关重要。...
java java_leetcode题解之Maximum XOR of Two Numbers in an Array.java
It’s basically due to the combination of two factors: cloud computing and the need to scale up and down quickly. Cloud computing makes it convenient to deploy thousands of small serv‐ ices; scaling...
8. 数据结构设计问题:如Median of Two Sorted Arrays(两个有序数组的中位数),这要求候选人具备设计新数据结构的能力,以解决特定问题。 9. 基于二分查找的问题:例如Search Insert Position(搜索插入位置),...
simple to compare two integer in java
we offer you two ways to license matlab r2012a: standalone 1) choose "install manually without using the internet" 2) enter the "file installation key" 38699-60149-36808-21840-05491 3) use "license...
Documentation is regularly updated to provide developers with in-depth information about new features in the Java platform. Some recent updates include: Swing The JLayer class has been added, which ...
For the engineer who is already proficient in Java, it would be a waste of time to study a Python textbook that begins with the basic concept of object-oriented programming, since the concept of OOP ...
In 1999, with his wife Luda and two daughters, he emigrated to the USA and has been living in Colorado ever since, working as a Java programmer. In his free time, Nick likes to write and hike in the ...
In general, this trail introduces core API that was added to the Java Development Kit (JDK) for the 1.1 or 1.2 release. It also introduces one standard extension--servlets. To help you sort out which ...
Java for the Web with Servlets, JSP and EJB is the one book you need to master Java web ...In addition to excellent content, this book includes licenses to two Java web components from BrainySoftware....
The two packages arose from the need to evaluate alternate designs for the implementation of matrices in Java. Jama is based on a single matrix class within a strictly object-oriented framework. ...