?
Solved

ArrayList

Posted on 2006-04-24
5
Medium Priority
?
277 Views
Last Modified: 2010-03-31
Hi,
I am aware of the 3 types of ArrayList we have, but is there a way to create an ArrayList myArrayList of  size n and initialize all myArrayList[i] with int 1.( of couse without using a loop. :) )

Thanks
0
Comment
Question by:komlaaa
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16528862
myArrayList = new ArrayList(Arrays.asList(new int[] { 1, 1, 1, 1, 1, 1 }));
0
 

Author Comment

by:komlaaa
ID: 16529517
this approach i good but will be tedious if i size n=1000
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 16529561
int[] ints = new int[1000];
Arrays.fill(ints, 1);

// (the rest as before)
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 16530451
For an ArrayList use:

ArrayList list = new ArrayList(1000);
Collections.fill(list, new Integer(1));

> I am aware of the 3 types of ArrayList we have

What 3 types are you referring to?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16533346
:-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question