I have two lists with items (List 1 and List 2). I'll create a third one, here called list_mix, with 10 items, and it will receive:
- The 6 first positions or 60% of list1 and
- The 4 first positions or 40% of list2.
That new list (list_mix) should receive the items from the lists 1 and 2 randomly.
Here is an example: public class JoinLists {
public static void main(String[] args) {
List<String> list1 = new ArrayList<String>();
list1.add("dog","cat","rabbit","bat","zebra","bear","turtle","mouse","fly","bird");
List<String> list2 = new ArrayList<String>();
list2.add("bee","horse","mule","cow","fish","shark","lion","tiger","elephant","panther");
List<String> list_mix = new ArrayList<String>();
list_mix.addAll(list1);
list_mix.addAll(list2);
System.out.println("list1 : " + list1);
System.out.println("list2 : " + list2);
System.out.println("list_mix : " + list_mix);
}
What I want is the following result in list_mix: Output
list1 : [dog,cat,rabbit,bat,zebra,bear,turtle,mouse,fly,bird]
list2 : [bee,horse,mule,cow,fish,shark,lion,tiger,elephant,panther]
list_mix : [dog,bee,cat,horse,rabbit,mule,bat,cow,zebra,bear] //A list with 10 items, using 60% of list 1 and 40% of list 2
If I use ".addAll" I'll get all the items, but I want only the first ones of the two lists. How can I get this?