title: Java, For Loop in Class
body: <p>I'm a novice programmer and I am creating this program where I would like to create a list of booleans of size ten and then set all the values to false. As I have understood in Java one is not supposed to place code directly in a class without surrounding them by a method. However I want this to be done as soon as an instance of the class is created.</p>
  
  <p>My question is then where this should be done. Should I do this in a constructor, should I initialize the list with all its values or have I simply missed something making it completely fine to put a for loop directly in the class? Thanks.</p>
  
  <p>Some of my code was requested so this is the problem here:</p>
  
  <pre><code>boolean[] numKeysPressed = new boolean[10];
  
  
  for(int i = 0; i&lt;10; i++){
      numKeysPressed[i] = false;
  }
  </code></pre>