/** * @author lautturi.com * Java example: print 2d array without brackets and commas in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { int arr[][] = { {1,2,3,4},{5,6,7,8},{9,10,11,12} }; for (int i = 0; i < arr.length; i++) { // for each row String row = Arrays.toString(arr[i]).replace(",", "") // remove the commas .replace("[", "") // remove the left bracket .replace("]", "") // remove the right bracket .trim(); // remove trailing spaces from partially initialized arrays System.out.println(row); } } }
output:
1 2 3 4 5 6 7 8 9 10 11 12