Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7804819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:02:55+00:00 2026-06-02T02:02:55+00:00

If I have a 64 length java array i[], is there a quick way

  • 0

If I have a 64 length java array i[], is there a quick way to find out if every position in that array is “full”, other than looping through the entire array? I’m writing a Reversi AI and I need to know whether the entire array is full or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:02:56+00:00Added an answer on June 2, 2026 at 2:02 am

    Keep a flags variable of type long (which is 64 bits) and use it to track which array entries are ‘full’ by setting or clearing the relevant bit as appropriate. (You need to keep this in sync with your array entries.)

    If you use a 1 value for each bit to mean the relevant cell is full, the you can tell very quickly if the whole array is full by comparing the flag variable to -1L.

    Example implementation

    int[] grid = new int[64];
    long  full = 0L;
    
    // place a piece at a certain grid position
    grid[17] = 1;   // pretend 1 is the code for black
    full |= 1L << 17;   // set bit 17 in our "full" tracker
    
    // is the grid full?
    if (full == -1L)
         // yes it is!
    else
         // no it isn't
    

    You can be even more cunning, and use a flags variable to track the colour of each cell too, so you can avoid using arrays altogether. One variable tracks whether the given cell is occupied or not, and the other tracks the colour (0 for white, 1 for black, say).

    long colour = 0L;
    long full   = 0L;
    
    // set position 17 to white
    colour &= ~(1L << 17);    // clear the bit (white)
    full   |=  (1L << 17);    // set it to occupied
    
    // set position 42 to black
    colour |=  (1L << 42);    // set the bit (black)
    full   |=  (1L << 42);    // set it to occupied
    
    // is position 25 occupied?
    if ((full & (1L<<25)) != 0) {
        // yes, but what colour?
        if ((colour & (1L<<25)) != 0)
            // black
        else
            // white
    }
    
    // is the grid full?
    if (full == -1L)
         // yes it is!
    else
         // no it isn't
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to find out whether a Java function (or a constructor)
I have an array that I want to permutate randomly. In Java, there is
I have a quick question. I have an integer array in java that needs
Background: I have an N-length array of positive random numbers that are certain to
I am a newbie to Java. I have an array of objects that have
Is there a way in Java to write to disk a large array of,
I have an array of integers in Java that is initialized as follows: public
I have a java string, which has a variable length. I need to put
I have a field in my report that needs to have a length of
I have a java object (let's call it Foo ) with a length() method.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.