Results 1 to 5 of 5
Thread: Array constructors
- 11-05-2010, 04:26 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
Array constructors
Hello,
I have a beginner Java question about array constructors.
This is okay:
final int[] blah = { 45, -45 };
for (int i : blah ) { ; }
This is illegal but would be sweet:
for (int i : { 45, -45 } ) { ; }
This works but is ugly and greater space/time?
for (int i : new int[] { 45, -45 } ) { ; }
Comments?
TIA!
StanO
- 11-05-2010, 04:38 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
- 11-05-2010, 06:14 PM #3
- 11-05-2010, 08:14 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
You're sure that the compiler will create that array object just once and reuse it the next time the code that includes the loop is called?
If it gets created each time the loop is called, then it is not-only ugly...
Clearly, the first case will only get constructed once.
Thanks again!
- 11-05-2010, 09:01 PM #5
Similar Threads
-
Constructors
By suresh.sa in forum New To JavaReplies: 5Last Post: 10-20-2010, 12:10 AM -
Constructors?
By annna in forum New To JavaReplies: 3Last Post: 01-27-2010, 10:51 PM -
constructors?
By shroomiin in forum New To JavaReplies: 4Last Post: 10-13-2009, 02:14 PM -
Constructors
By new2java2009 in forum New To JavaReplies: 5Last Post: 08-18-2009, 06:46 AM -
Help with constructors
By Minime in forum New To JavaReplies: 3Last Post: 04-09-2008, 07:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks