“Java Join Array” Code-Antworten

Java Join Array


String.join(delimiter, elements);

Better Bug

Schließen Sie sich Arrays in Java an

// Java Program to demonstrate merging
// two array using pre-defined method
  
import java.util.Arrays;
  
public class MergeTwoArrays1 {
    public static void main(String[] args)
    {
        // first array
        int[] a = { 10, 20, 30, 40 };
  
        // second array
        int[] b = { 50, 60, 70, 80 };
  
        // determines length of firstArray
        int a1 = a.length;
        
        // determines length of secondArray
        int b1 = b.length;
        
        // resultant array size
        int c1 = a1 + b1;
  
        // create the resultant array
        int[] c = new int[c1];
  
        // using the pre-defined function arraycopy
        System.arraycopy(a, 0, c, 0, a1);
        System.arraycopy(b, 0, c, a1, b1);
  
        // prints the resultant array
        System.out.println(Arrays.toString(c));
    }
}
Naval

Java Join Array

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 Array”

Fragen ähnlich wie “Java Join Array”

Weitere verwandte Antworten zu “Java Join Array” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen