I have this method which add spaces to the start of byte array. problem is that I am not sure if this is the most faster implementation of this task. Is there some options to add space faster ? if yes please add here some sollution
public static byte[] doplnMezery(byte[] item, int numberOfSpaces) {
int lenghtOfItem = item.length;
for (int i = lenghtOfItem; i < numberOfSpaces; i++) {
item = ArrayUtils.add(item, 0, (byte) 32);
}
return item;
}
That seems inefficient since the
addmethod can’t run faster than linear time. What you get here is a quadratic algorithm.Something like this should be faster (linear time complexity).