String Integer Array Conversion

Asked

Viewed 3,327 times

2

I’m a beginner in Java and would like to learn how to convert an array of integers into a String.

  • 4

    Convert as? Type, if your array has the elements 10, 20 and 30 the resulting string must be "102030"? Please clarify your problem better, show us where you’re going and what you’ve been able to do so far (i.e. tell us what you know, so we can help you in what you don’t know).

1 answer

6

To convert a type matrix int for a string you should make use of the method .toString() which is part of class java.util.Arrays:

Returns a string representation of the Contents of the specified array.

That translated:

Returns a string representation of the content of the specified matrix.

Example:

Demonstration in ideone.com

import java.util.Arrays;

public class Main {
    public static void main(final String[] args) {

        final int[] matriz = new int[] { 1, 2, 3 };
        System.out.println(Arrays.toString(matriz));
    }
}

Upshot:

[1, 2, 3]

Browser other questions tagged

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