Como inicializar um Array bidimensional?

3 respostas
andre_teprom

Olá Pessoal…

Seguinte : Catei essa informação na Web e nesse forum, mas não encontrei nada.
Gostaria de inicializar o seguinte vetor estaticamente :

static String ErrorTable[][] = new String {  [ "E01" , "E02","E03"] , [ "descricao erro 1","descricao erro 2","descricao erro 3" ] } ;

Mas está retornando erro :
Multiple markers at this line

- Syntax error, insert “)” to complete VariableInitializer
- Syntax error on token “[”, ( expected
- Watchpoint:Principal [access and modification] -
ErrorTable
- Syntax error on token “{”, delete this token
- Syntax error on tokens, delete these tokens

Alguem pode ajudar a resolver ?

Obg.

+++

3 Respostas

josemanzoli
public static String ErrorTable[][] = {{"E01" , "E02","E03"},{ "descricao erro 1","descricao erro 2","descricao erro 3" }};

http://www.guj.com.br/java/37392-vetor-e-matriz-em-java-/1

A

Paga ai chara

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package teste;

/**
 *
 * @author Andre Lima Ferreira
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

         String[][] b ={{"1","2","3"},{"1","2","3"}};

        for(int i = 0;i < 2;i++)
            for(int j = 0;j<3;j++)
            System.out.println(b[i][j]);
    }

}
andre_teprom

Obrigado pessoal…!!!

+++

Criado 4 de janeiro de 2011
Ultima resposta 5 de jan. de 2011
Respostas 3
Participantes 3