print Tagged Byte Array - Java java.lang

Java examples for java.lang:byte Array to int

Description

print Tagged Byte Array

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String tag = "java2s.com";
        byte[] byteArray = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        printTaggedByteArray(tag, byteArray);
    }/*w  w  w.  j a  v a2  s  .  com*/

    public static void printTaggedByteArray(String tag, byte[] byteArray) {
        StringBuilder sb = new StringBuilder();
        sb.append(tag);

        for (int i = 0; i < byteArray.length; i++)
            sb.append(String.format("%02X ", byteArray[i]));

        System.out.print(sb.toString());
    }

    public static void printTaggedByteArray(String beginTag,
            byte[] byteArray, String endTag) {
        StringBuilder sb = new StringBuilder();
        sb.append(beginTag);

        for (int i = 0; i < byteArray.length; i++)
            sb.append(String.format("%02X ", byteArray[i]));

        sb.append(endTag);
        System.out.print(sb.toString());
    }
}

Related Tutorials