I'm using a book to self-study Java. One of my exercises needs an array with boolean values. When I try to use Arrays.fill(myArray, false) as indicated below I get a compiler errors. Plus the IDE complains.
...\ArrayFill.java:6: <identifier> expected
...\ArrayFill.java:6: <identifier> expected
...\ArrayFill.java:6: illegal start of type
Here's the code:
import java.util.Arrays;
public class ArrayFill {
boolean[] myArray = new boolean[4]; // Declaration OK.
Arrays.fill( myArray, false); // Not OK.
// boolean[] myArray = {false, false, false, false }; // Manually OK.
public void makeReservation(){
Arrays.fill(myArray, false); // In a method, OK.
}
}
It seems like it has something to do with the fact that Arrays.fill is a static method but I can't find the answer why. Am I close?
Arrays.fillspecifically.