-1

intArray = {2,3,4,1,5}

I want this int array to be represented as

2 3 4 1 5

Without using loops is there any way to do this?

when i tried System.out.println(" ".join(a));

error message as follows.

error: incompatible types: int[] cannot be converted to CharSequence

0

2 Answers 2

1
int[] arr = new int[]{2, 3, 4, 1, 5};
String res = Arrays.toString(arr).replaceAll("[\\[\\],]", "");
System.out.println(res);
Sign up to request clarification or add additional context in comments.

Comments

0

Java's way of doing this.

import java.util.*;

class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        System.out.println(Arrays.toString(arr).replace(",", "").replace("[", "").replace("]", ""));
    }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.