“Java Join List” Code-Antworten

Java Join List


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

Prickly Platypus

Java treten zwei Liste bei

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]
abdullah

Java Join List als String

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

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

Schließen Sie sich den Elementen in einer Liste an, Java

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

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
Merlin4 (personal)

Ähnliche Antworten wie “Java Join List”

Fragen ähnlich wie “Java Join List”

Weitere verwandte Antworten zu “Java Join List” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen