# Boolean array and sorting the elements within it

Page 1 of 1

## 6 Replies - 580 Views - Last Post: 26 May 2014 - 09:22 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=347501&amp;s=7f6c26d1e0c2c52d5990ff10fb24b45e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Tash.

• New D.I.C Head

Reputation: 0
• Posts: 17
• Joined: 30-July 11

# Boolean array and sorting the elements within it

Posted 24 May 2014 - 08:24 AM

If I have a boolean array that contains 30 elements (boolean[] fish), how do I go about isolating every 10 elements to use for something specific?

Say there are 30 types of fish stored within the boolean array and 0-9 are fish found specifically in the Indian Ocean, 10-19 are fish found specifically in the Atlantic, and 20-29 are fish specifically found in the Pacific Ocean. And for those 10 fish [0-9], [10-19], [20-29], each is a different color (red, orange, green, blue, white, black, silver, yellow, purple and gold), where the colors and locations of the fish are enum types Colors and Locations.

How do I go about appointing those characteristics to the fish?

Ex: elements [0-9] are fish from the Indian Ocean and [0] is red, [1] is orange, [2] is green, [3] is blue, [4] is white, [5] is black, [6] is silver, [7] is yellow, [8] is purple, and [9] is gold.

elements [10-19] are fish from the Atlantic Ocean and [10] is red, [11] is orange, [12] is green, [13] is blue, [14] is white, [15] is black, [16] is silver, [17] is yellow, [18] is purple, and [19] is gold.

elements [20-29] are fish from the Indian Ocean and [20] is red, [21] is orange, [22] is green, [23] is blue, [24] is white, [25] is black, [26] is silver, [27] is yellow, [28] is purple, and [29] is gold.

Will I need to appoint those characteristics in the constructor after initializing fish = new boolean[30]?

Is This A Good Question/Topic? 0

## Replies To: Boolean array and sorting the elements within it

### #2 baavgai

• Dreaming Coder

Reputation: 6381
• Posts: 13,633
• Joined: 16-October 07

## Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 09:23 AM

Sorry, this doesn't make much sense. A boolean array is simply an array of boolean values. The values are true or false. Period.

Now, if each position is a flag of some sort, like 2 is Green Indian Ocean fish, then you could use your boolean array to store characteristics of one fish. Though, if it's Green in one ocean, do you expect it to be red in another? That sounds like a different fish.

You would reasonably want a Fish class in Java with the elements that make sense:
class Fish {
public String getName() { /* your code here */ }
public Color getColor() { /* your code here */ }
public Ocean getOcean() { /* your code here */ }
public Fish(String name, Color color, Ocean ocean) {
// your code here
}

Fish [] fishes = new Fish[30]; // now you can store 30 different kinds of fish

Hope this helps.
Was This Post Helpful? 1

### #3 Tash.

• New D.I.C Head

Reputation: 0
• Posts: 17
• Joined: 30-July 11

## Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 09:41 AM

Thank you very much for responding. My professor wants us to use the boolean array to search for an element, and if the element is in the array, it will return True. If not, it will return False. If I end up creating a second array that contains the fish elements, how will I make use of the boolean array? The boolean array becomes pointless, do it not?
Was This Post Helpful? 0

### #4 baavgai

• Dreaming Coder

Reputation: 6381
• Posts: 13,633
• Joined: 16-October 07

## Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 10:36 AM

Yes, a boolean array seems pointless. Having a search function that looks through an array and returns boolean ( just a single boolean value, not an array) does make sense.

Ask your professor to clarify how a boolean array should be used because it sounds, um, fishy as this point.
Was This Post Helpful? 0

### #5 g00se

• D.I.C Lover

Reputation: 3107
• Posts: 13,403
• Joined: 20-September 08

## Re: Boolean array and sorting the elements within it

Posted 24 May 2014 - 11:37 AM

Sounds like you want two EnumSet of colour and location in Fish. You can use Fish.equals with iteration to test for a given one's presence in an array or use a Collection
Was This Post Helpful? 0

### #6 program94

• New D.I.C Head

Reputation: 1
• Posts: 23
• Joined: 19-April 14

## Re: Boolean array and sorting the elements within it

Posted 26 May 2014 - 08:04 AM

What kind of search are you suppose to use?
Was This Post Helpful? 0

### #7 NormR

• D.I.C Addict

Reputation: 108
• Posts: 657
• Joined: 25-December 13

## Re: Boolean array and sorting the elements within it

Posted 26 May 2014 - 09:22 AM

Also posted at: http://www.javaprogr...html#post148597
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }