Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #16893

Re: initialize an array of booleans

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: initialize an array of booleans
Date 2012-07-31 13:08 -0700
Organization http://groups.google.com
Message-ID <9ff73f81-f913-40a6-995b-0f7704623b6d@googlegroups.com> (permalink)
References <1db13953-d741-4f7d-ad9a-27ca5b194884@googlegroups.com>

Show all headers | View raw


On Tuesday, July 31, 2012 12:58:58 PM UTC-7, bob smith wrote:
> Is there any easy way to initialize an array of booleans like this?
> 
> 
> 
> boolean b[] = new boolean(false)[100];

boolean b[] = new boolean [100];

<http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.10.1>

If you want to initialize array elements to a value that is not the default you have to loop.

Or use the 'java.util.Arrays' class.
<http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#fill(boolean[], boolean)>

Every Java programmer should know the collections framework and key utility classes like 'Arrays'.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

initialize an array of booleans bob smith <bob@coolfone.comze.com> - 2012-07-31 12:58 -0700
  Re: initialize an array of booleans Lew <lewbloch@gmail.com> - 2012-07-31 13:08 -0700
  Re: initialize an array of booleans Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-31 16:12 -0400
  Re: initialize an array of booleans Roedy Green <see_website@mindprod.com.invalid> - 2012-07-31 14:08 -0700

csiph-web