Archive for January, 2017

Read list as a block

public class Test {

public static void main(String[] args) {

int[] adresTo = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

int BLOCK_SIZE = 4;
int listLength = adresTo.length;
int numberOfBlocks = listLength / BLOCK_SIZE + 1;

System.out.println(“numberOfBlocks:” + numberOfBlocks);

int from = 0;
int to = BLOCK_SIZE;

if (numberOfBlocks <= 1) {
sendEmail(adresTo);
} else {

for (int i = 0; i < numberOfBlocks; i++) {
senEmail(Arrays.copyOfRange(adresTo, from, to));

from = to;

if (i < numberOfBlocks – 2) {
to = to + BLOCK_SIZE;
} else {
to = listLength;
}

}
}

}

public static void sendEmail(int[] emails) {

System.out.println(“blocks:”);
for (int a : emails) {
System.out.println(a);
}

}

}

Advertisements

Leave a comment