Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java string join arraylist

// You can't just do String.join(", ", list) because
// the list has to be a String[]. This code works on
// everything.

list.stream().map(Object::toString).collect(Collectors.joining(", "));
Comment

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 of strings

String result = String.join(",", list);
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

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 16 raspberry pi 
Java :: how to add to a file in java 
Java :: how to initialise array in java without size 
Java :: optional throw if present 
Java :: java launch exe 
Java :: java collection to list 
Java :: convert int to string java 
Java :: pi in java 
Java :: how to add elements to an empty array in java 
Java :: iterator java 
Java :: array liste java 
Java :: java jframe example 
Java :: use findviewbyid in fragment 
Java :: comment in java 
Java :: java argument main 
Java :: how to create a stack data structure in java? 
Java :: java get file from url 
Java :: slice a list java 
Java :: Cannot invoke toString() on the primitive type int 
Java :: select in selenium java 
Java :: JAVA HashMap get keys by values 
Java :: how to add input in array java 
Java :: how to summon lightning in minecraft 
Java :: android play sound file from assets 
Java :: java remove duplicates 
Java :: materialbutton remove shadow xml 
Java :: awk print second 
Java :: get preference value android 
Java :: How to perform quick sort, in Java? 
Java :: date format in java 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =