Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String toHexString(int[] data) {
        if (data == null)
            return "null";
        StringBuilder stringBuilder = new StringBuilder(data.length * 5);
        stringBuilder.append('[');
        for (int i = 0; i < data.length; i++) {
            stringBuilder.append(String.format("0x%02X", data[i]));
            if (i + 1 < data.length)
                stringBuilder.append(", ");
        }
        return stringBuilder.append(']').toString();
    }

    public static String toHexString(byte[] data) {
        if (data == null)
            return "null";
        StringBuilder stringBuilder = new StringBuilder(data.length * 5);
        stringBuilder.append('[');
        for (int i = 0; i < data.length; i++) {
            stringBuilder.append(String.format("0x%02X", data[i]));
            if (i + 1 < data.length)
                stringBuilder.append(", ");
        }
        return stringBuilder.append(']').toString();
    }
}