I have two arrays:
a = ["a","b","c"]
b = ["d","e","f"]
How can I merge them into a single array, like so:
c = ["a=d", "b=e", "c=f"]
using the equals sign (=) as a delimiter between the merged strings?
I have two arrays:
a = ["a","b","c"]
b = ["d","e","f"]
How can I merge them into a single array, like so:
c = ["a=d", "b=e", "c=f"]
using the equals sign (=) as a delimiter between the merged strings?
 
    
     
    
    You can do it with the help of a loop e.g.
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        String[] a = { "a", "b", "c" };
        String[] b = { "d", "e", "f" };
        String[] result = new String[a.length];
        for (int i = 0; i < Math.min(a.length, b.length); i++) {
            result[i] = a[i] + "=" + b[i];
        }
        System.out.println(Arrays.toString(result));
    }
}
Output:
[a=d, b=e, c=f]
Learn more about loops at this tutorial from Oracle.
Using IntStream:
import java.util.Arrays;
import java.util.stream.IntStream;
public class Main {
    public static void main(String[] args) {
        String[] a = { "a", "b", "c" };
        String[] b = { "d", "e", "f" };
        String[] result = IntStream
                            .range(0, Math.min(a.length, b.length))
                            .mapToObj(i -> a[i] + "=" + b[i])
                            .toArray(String[]::new);
        
        System.out.println(Arrays.toString(result));
    }
}
