Java Array to String convertByteToString(byte[] objectGuid)

Here you can find the source of convertByteToString(byte[] objectGuid)

Description

convert Byte To String

License

Open Source License

Declaration

public final static String convertByteToString(byte[] objectGuid) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.Collection;

public class Main {
    public final static String convertByteToString(byte[] objectGuid) {
        StringBuilder builder = new StringBuilder();
        for (byte element : objectGuid) {
            int item = element & 0xFF;
            if (item <= 0xF) {
                builder.append("0");
            }//from  w w w. j  a v  a2s  .  c  om
            builder.append(Integer.toHexString(item));
        }
        return builder.toString();
    }

    public static String toString(String delimiter, String... values) {
        if (values == null) {
            return "";
        }
        return toString(Arrays.asList(values), delimiter);
    }

    /**
     * Convert a collection of string values into a delimited string.
     * 
     * @param values
     * @param delimiter delimiter string
     * @return delimited string
     */
    public static String toString(Collection<String> values, String delimiter) {
        if (values == null) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        int delim = 0;
        for (String value : values) {
            if (builder.length() > 0) {
                builder.append(delimiter);
            }
            for (char ch : value.toCharArray()) {
                if (delim < delimiter.length() && ch == delimiter.charAt(delim)) {
                    delim++;
                    if (delim == delimiter.length()) {
                        builder.append('\\');
                        builder.append(delimiter);
                        delim = 0;
                    }
                } else if (ch == '\n') {
                    builder.append("\\n");
                } else if (ch == '\r') {
                    builder.append("\\r");
                } else if (ch == '\t') {
                    builder.append("\\t");
                } else if (ch == '\\') {
                    builder.append("\\\\");
                } else {
                    builder.append(ch);
                }
            }
        }

        return builder.toString();
    }
}

Related

  1. convertArrayToString(String[] array, String separator)
  2. convertArrayToString(String[] array, String separator)
  3. convertArrayToString(String[] fields, String delimiter)
  4. convertArrayToString(String[] idArray)
  5. convertArrayToString(String[] strArray)
  6. convertToString(String[] args)
  7. convertToString(String[] values, String separator)
  8. deepToString(Object[] a)
  9. encodedSeptetsToString(byte[] encodedSeptets)