How to transform a string into an array

Asked

Viewed 112 times

0

Good guys, next how can I turn a string into an array? For example: String test = "345,421,888,211";

Explaining the context, these values are Id’s that I concatenated into a string from a grid. After transforming them into an array, enter the other doubt, as I go through the array?

Ps: I am beginner in java, it would be helpful this information.

1 answer

4

I think it helps you..

String teste = "345,421,888,211";

    //Vou dividir a string quando encontrar o caractere ","
    String[] teste2 = teste.split(",");

    //Aqui vou percorrer o array criado e printar o código
    for(int i=0; i<teste2.length; i++) {
        System.out.println("Codigo:" + teste2[i]);
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.