How to transform a Java String into a Java Array Object?

Asked

Viewed 369 times

2

On a . jsp page, I have the following code:

String[] arrayRegioes = request.getParameterValues("numRegiaoUsuario");//objeto

When I print the arrayRegioes, the value shown is:

[Ljava.lang.String;@5a879b45

Now, I need to turn a string that was made in the hand:

[55826586566, 54555555454, 994139792]

On an object array, as the format of that informed above.

  • 2

    System.out.println(Arrays.toString(arrayRegioes)) will print the array correctly (i.e., will print the list of elements instead of [Ljava.lang.String;@5a879b45).

  • Int or String array?

1 answer

3


You could try wearing something like that. PS: I didn’t test it, it’s just something I remember from college.

String[] array = values.split(",");

If there can be a string with null values, you must use a second parameter, following example.

String[] array = values.split("\\|", -1);
  • 3

    In the case of OP it will probably have to remove the first and last characters too ([, ]), this can be done with substring or replace.

  • To create the array, I have to remove the brackets from the string ?

  • Error occurred: "The type of the Expression must be an array type but it resolved to String"

Browser other questions tagged

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