title: Java: How to initialize int array in a switch case?
body: <p>How can I initialize an integer array in Java like so: <code>int[] array = {1,2,3};</code> inside a switch statement?</p>
  
  <p>Currently, I can write:</p>
  
  <pre><code>switch(something) {
      case 0: int[] array = {1,2,3}; break;
      default: int[] array = {3,2,1};
  }
  </code></pre>
  
  <p>But when I try to access the <code>array</code> variable, eclipse will complain that it might not be initialized.</p>
  
  <p>If I try to declare it like <code>int[] array;</code> or <code>int[] array = new int[3];</code> and then have the switch statement, it would say I am trying to redeclare it.</p>
  
  <p>How can I resolve this issue? Final idea is to be able to initialize an array with 10 values in just one line of code, based on some logic (a switch statement).</p>