Java Utililty Methods Array Print

List of utility methods to do Array Print

Description

The list of methods to do Array Print are organized into topic(s).

Method

voidprintArray(int[] array)
print Array
for (int i : array) {
    System.out.print(i + " ");
System.out.println();
StringprintArray(int[] array)
Pretty prints an array of ints as a string.
StringBuilder result = new StringBuilder("[");
for (int i = 0; i < array.length; i++) {
    result.append(array[i]).append((i < (array.length - 1)) ? ", " : "");
result.append(']');
return result.toString();
voidprintArray(int[] array)
print Array
System.out.print("{");
for (int i = 0; i < array.length; i++) {
    System.out.print(array[i]);
    if (i < array.length - 1) {
        System.out.print(", ");
System.out.println("}");
...
voidprintArray(int[] array)
print Array
System.out.println(Arrays.toString(array));
voidprintArray(int[] array)
print Array
boolean firstFlag = true;
StringBuffer logBuffer = new StringBuffer();
for (int i : array) {
    if (firstFlag) {
        logBuffer.append("[" + i);
        firstFlag = false;
    } else {
        logBuffer.append(", " + i);
...
voidprintArray(int[] array)
print Array
for (int i = 0; i < array.length; i++) {
    System.out.print(array[i] + ", ");
System.out.println();
voidprintArray(int[] array, int start, int end)
print Array
System.out.print("array: [" + start + "," + end + "]");
for (int i = start; i < end; i++) {
    System.out.print("," + array[i]);
System.out.println("");
voidprintArray(int[] nums)
print Array
for (int i : nums) {
    System.out.print(i + ", ");
System.out.println();
voidprintArray(Object a[])
Prints the contents of the array.
for (int i = 0; i < a.length; i++)
    System.out.print(a[i].toString() + " ");
StringprintArray(Object[] arr)
Prints an array of stuff, with the notation {x1,x2,x3...,xn}, or "" if the array is empty.
String toPrint = "";
if (arr.length > 0) {
    toPrint = "{";
    for (int i = 0; i < arr.length; i++) {
        toPrint += arr[i].toString();
        if (i < arr.length - 1)
            toPrint += ",";
    toPrint += "}";
return toPrint;