| Author |
Initializing Arrays
|
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
How many ways can an array be initialized? I remember someone had a very odd way of initializing an array but I can't remember how it was done. I know there is... String myStrings[] = {"blah", "blah"}; String myString[] = new String[2]; Are there others? Thanks Dale
|
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
|
 |
Rick Salsa
Ranch Hand
Joined: Jul 17, 2001
Posts: 173
|
|
You could also do: int a[]=new int[] {1,2,3,4}; int b[][] = new int[3][]; int b[][] = new int[3][3]; That's all I can think of off the top if my head. /rick
|
 |
Brian Lugo
Ranch Hand
Joined: Nov 10, 2000
Posts: 165
|
|
For One Dimensional arrays here is one more: String myString[] = new String[] {"blah", "blah",}; Note the comma in the end - it is allowed in Java. Brian
|
 |
Rajinder Yadav
Ranch Hand
Joined: Jan 18, 2002
Posts: 178
|
|
Here is one more! Class A {} A ref[] = {new A(), new A(), new A()};
|
<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
|
 |
 |
|
|
subject: Initializing Arrays
|
|
|