Hey there! any question in your mind? Ask It Now!.

Popular Categories





How can i add multiple Arrays in an Array List?

+2 votes
108 views
asked in Programming by Kaperly (1,610 points)

I am using this for adding multiple Arrays in an Array List, but not working can you tell me how can i do this?

Thanks for your answer!

    

static int elements = 13; 
public static void main(String[] args)
    {
        int[] person = new int[4];
        ArrayList personID = new ArrayList();

        experiment(personID, person);
    }
private static void experiment(ArrayList personID, int[] person)
    {
        for(int i = 0; i < elements; i++)
            {
                person[0] = i;
                person[1] = i;
                person[2] = i;
                person[3] = i;

                personID.add(person);
            }
        System.out.print(personID);
    }



1 Answer

0 votes
answered by jazs (1,220 points)

I think you should use this when you are printing personID

for (int[] a : personID)

System.out.println(Arrays.toString(a));

Related Questions

–1 vote
0 answers 126 views
0 votes
0 answers 71 views
+5 votes
1 answer 116 views
asked in Programming by jatin Expert (3,823 points)
+2 votes
1 answer 607 views
0 votes
1 answer 112 views
+2 votes
3 answers 292 views
asked in Programming by jatin Expert (3,823 points)
+2 votes
1 answer 153 views
–1 vote
0 answers 375 views
+1 vote
0 answers 44 views
+8 votes
1 answer 98 views

Not a Member yet?

Ask to Folks Login

My Account
693 Folks are online
0 members and 693 guest online
Your feedback is highly appreciated