title: How to define a multidimensional array in Java using curly braces?
body: <p>I don't understand the behaviour of Java about arrays. It forbids to define an array in one case but allows the same definition in another.</p>
  
  <p>The example from tutorial:</p>
  
  <pre><code>String[][] names = {
          {"Mr. ", "Mrs. ", "Ms. "},
          {"Smith", "Jones"}
      };
  System.out.println(names[0][0] + names[1][0]);    // the output is "Mr. Smith";
  </code></pre>
  
  <p>My example:</p>
  
  <pre><code>public class User {
     private static String[][] users;
     private static int UC = 0;
  
     public void addUser (String email, String name, String pass) {
        int i = 0;
  
        // Here, when I define an array this way, it has no errors in NetBeans
        String[][] u = { {email, name, pass}, {"one@one.com", "jack sparrow", "12345"} };
  
        // But when I try to define like this, using static variable users declared above, NetBeans throws errors
        if (users == null) {
           users = { { email, name, pass }, {"one", "two", "three"} };    // NetBeans even doesn't recognize arguments 'email', 'name', 'pass' here. Why?
  
           // only this way works
           users = new String[3][3];
           users[i][i] = email;
           users[i][i+1] = name;
           users[i][i+2] = pass;
           UC = UC + 1;
        }
      }
  </code></pre>
  
  <p>The mistakes thrown by NetBeans are: </p>
  
  <p><em>illegal start of expression,</em> </p>
  
  <p><em>";" expected</em>, </p>
  
  <p><em>not a statement</em>. </p>
  
  <p>And also it doesn't recognize arguments <code>email</code>, <code>name</code>, <code>pass</code> in the definition of the <code>users</code> array. But recognizes them when I define <code>u</code> array.</p>
  
  <p>What is the difference between these two definitions? Why the one works but the another one defined the same way doesn't?</p>