I have a set of records(say 1000) residing in flat files(.txt). I need to extract them and put them in buckets. Each bucket has an upper cap of 300 records. Which means I'll need 4 buckets. I need to print them out to an excel sheet. Each time I hit the cap I'm suppose to print the bucket no.
eg:
Bucket 1
- rec 1,
- rec 2,
- ...
- rec 300
Bucket 2
- rec 301,
- rec 302,
- ... -rec 600
Bucket 3
and so on. Whats the best most efficient way to do it? Here is what I am doing:
int lim = 300;
if(vector.size()>lim){
n = Math.ceil((double) (vector.size() / 300.0));
}else{
n=1;
}
//I'm meant to hard-code the bucket names
String[] name = {"Bucket1","Bucket2","Bucket3","Bucket4"};
for(int j=0; j<n;j++){
buf.append("\n\t\t Name:"+name[0]);
for(int i=0; i<size;i++){
if (i > 0 && i < lim) {
buf.append(",");
}
if (i < lim) {
buf.append("\n\t\t\t\tP:" + vector.get(i));
}
}
size = size - lim;
}