Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java join list


List<String> list = Arrays.asList("foo", "bar", "baz");
String joined = String.join(" and ", list); // "foo and bar and baz"

Comment

java join list as string

List<String> list = Arrays.asList("a","b","c");
String result = String.join(",", list);

System.out.println(result);		//prints a,b,c
Comment

java join two list

import java.util.ArrayList;
import java.util.List;

public class JoinLists {

    public static void main(String[] args) {

        List<String> list1 = new ArrayList<String>();
        list1.add("a");

        List<String> list2 = new ArrayList<String>();
        list2.add("b");

        List<String> joined = new ArrayList<String>();

        joined.addAll(list1);
        joined.addAll(list2);

        System.out.println("list1: " + list1);
        System.out.println("list2: " + list2);
        System.out.println("joined: " + joined);

    }
}
//output
list1: [a]
list2: [b]
joined: [a, b]
Comment

join elements in a list with , java

Joiner joiner = Joiner.on("+");
String join = joiner.join(joinList);
Comment

java join list

String[] data = { "First", "Second", "Third" };
StringBuilder sb = new StringBuilder();
for (String item : data) {
  sb.append(item).append(", ");
}
sb.setLength(sb.length() - 2);

// generates output:
// First, Second, Third
Comment

PREVIOUS NEXT
Code Example
Java :: java exception message 
Java :: java restart while loop 
Java :: set ImageView size programmatically android 
Java :: image cropper implementation 
Java :: split method in java 
Java :: how to print to the console in java 
Java :: java add to map 
Java :: android xml hide 
Java :: reverse a integer in java 
Java :: int array java 
Java :: string length in java 
Java :: get the image from camera click in android 
Java :: integer to string java 
Java :: byte array to file java 
Java :: compare two times in java 
Java :: remove first and last character from string in java 
Java :: Array list deep copy 
Java :: array sort java 
Java :: how to remove null values collections 
Java :: get minimum of array java 
Java :: javac clear 
Java :: java string to number 
Java :: javafx textarea size 
Java :: java coalesce 
Java :: java string to integer 
Java :: java replace element in list 
Java :: spring filter exception handling 
Java :: multiplication program java 
Java :: java input string with spaces 
Java :: java sql query with parameters 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =