Java String Split by Separator split(byte[] b, int separator)

Here you can find the source of split(byte[] b, int separator)

Description

split

License

Apache License

Declaration

public static List<byte[]> split(byte[] b, int separator) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<byte[]> split(byte[] b, int separator) {
        List<byte[]> result = new ArrayList<byte[]>();
        int i = 0;
        while (i < b.length) {
            int e = indexOf(b, separator, i);
            if (e == -1) {
                break;
            }//from   w ww  .  j  a va 2s . c om
            byte[] dest = new byte[e - i];
            System.arraycopy(b, i, dest, 0, dest.length);
            result.add(dest);
            i += dest.length + 1;
        }
        byte[] dest = new byte[b.length - i];
        System.arraycopy(b, i, dest, 0, dest.length);
        result.add(dest);
        return result;
    }

    public static int indexOf(byte[] b, int element, int fromIndex) {
        for (int i = fromIndex; i < b.length; i++) {
            if (b[i] == element) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. fastSplit(final String text, char separator)
  2. fastSplit(String text, char separator)
  3. split(CharSequence seq, char separator)
  4. split(final String expression, final char separator)
  5. split(final String input, final String separator)
  6. split(final String iSource, final char iRecordSeparator, final char... iJumpCharacters)