how can I fill the two lists with corresponding elements in method fillArrayList the user must enter the values
import java.util.ArrayList;
import java.util.Scanner;
class Assignment1
{
public static void main(String[] args)
{
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
System.out.println("Enter your lists = ");
fillArrayList(list1,list2);
}
public static void fillArrayList(ArrayList<Integer> L1 ,ArrayList<Integer> L2 )
{
//don't know what to do here to fill two lists from the user , really need help
}
I think you should modify your
fillArrayListsignature to just fill one list at a time. And you can invoke it twice for your two arraylist.So, your method should be like: –
Then declare your two lists as instance variable, outside the main method. And use
Listfor reference type.Now, from the main method, you can invoke this method twice for each list like this: –
And back in your main method, you can print your list, as the change you do in
fillArrayListmethod will get reflected there also.