This code gives me an output of -
first_name- [Tiger, Enrique]
family_name- [Woods, Iglesias]
import java.util.*;
public class al_Concatenate {
public static void main(String args[]) {
// creating array list
ArrayList<String> first_name = new ArrayList<String>();
ArrayList<String> family_name = new ArrayList<String>();
Arraylist<String> name = new Arraylist<String>();
// add elements to the array list
first_name.add("Tiger");
first_name.add("Enrique");
family_name.add("Woods");
family_name.add("Iglesias");
name.??
//displaying the output
System.out.println("first_name- " + first_name);
System.out.println("family_name- "+ family_name);
System.out.println("name- "+ name);
}
}
But I need and output like this (without using loop, preferably a single line code)-
name - [Tiger Woods, Enrique Iglesias]
thanks in advance
I would also like to add that the size of the arraylist is 2, but in my real program it's around 4500. I created this example to make it simple :) I edited the post a bit, sorry for making it cumbersome :(
fisrtName.get(0) + " " + family_name.get(0)...?ArrayListsin the way you describe.ArrayLists; the first declaration should beArrayList<String> first_name = new ArrayList<>();.