-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

ajaysurya
  • 3
  • 4

2 Answers2

1
int[] arr = new int[]{2, 3, 4, 1, 5};
String res = Arrays.toString(arr).replaceAll("[\\[\\],]", "");
System.out.println(res);
AleFlash
  • 26
  • 2
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("]", ""));
    }
}