bytes Range To String - Java java.lang

Java examples for java.lang:byte Array to String

Description

bytes Range To String

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] bytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        int from = 2;
        int to = 2;
        System.out.println(bytesRangeToString(bytes, from, to));
    }/*from ww w  .j ava  2s  . c  o  m*/

    public static String bytesRangeToString(byte[] bytes, int from, int to) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = from; i <= to; i++)
            stringBuilder.append((char) bytes[i]);

        return stringBuilder.toString();
    }
}

Related Tutorials