Java examples for java.lang:byte Array
Return last position of sequence of symbol in byte array
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { byte[] btBuff = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; int iOffset = 2; byte btSearch = 2; System.out.println(lastIndexOfSequence(btBuff, iOffset, btSearch)); }/*w w w . j a v a 2 s. c o m*/ /** * Return last position of sequence of symbol in byte array * @param btBuff buffer to search * @param iOffset start offset * @param btSearch symbol to search * @return first position of symbol in buffer, -1 if not found * @author Thai Hoang Hiep */ //////////////////////////////////////////////////////// public static int lastIndexOfSequence(byte[] btBuff, int iOffset, byte btSearch) { while (iOffset < btBuff.length && btBuff[iOffset] == btSearch) iOffset++; if (iOffset >= btBuff.length) return -1; return iOffset; } }