Last active
August 29, 2015 14:14
-
-
Save adityasatrio/7035e3f5534d5f097b45 to your computer and use it in GitHub Desktop.
Java Codes for separated List per 100.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
public class Loop { | |
public static void main(String[] args) { | |
List<String> elementList = new ArrayList<String>(); | |
for (int i = 0; i < 257; i++) { | |
elementList.add(i + "value"); | |
} | |
System.out.println("DATA ASELI ==========================================="); | |
for (String str : elementList) { | |
System.out.println(" value " + str); | |
} | |
System.out.println("==========================================="); | |
List<String> result = getListPerOneHundreds(elementList); | |
System.out.println("DATA SETELAH PROSES==========================================="); | |
for (String str : result) { | |
System.out.println(" value " + str); | |
} | |
System.out.println("==========================================="); | |
} | |
private static List<String> getListPerOneHundreds(List<String> elementList) { | |
Integer total = elementList.size(); | |
Integer selisih = total % 100; | |
Integer countLoop = (total - selisih) / 100; | |
Integer index = 0; | |
List<String> resultData = new ArrayList<String>(); | |
Integer limit = 100; | |
for (int i = 0; i < countLoop; i++) { | |
/* loop element per seratus index */ | |
for (int j = index; j < limit; j++) { | |
resultData.add(elementList.get(j)); | |
} | |
limit = limit + 100; | |
index = index + 100; | |
} | |
//populate selisih | |
for(int i = index; i < total; i++){ | |
resultData.add(elementList.get(i)); | |
} | |
return resultData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my trick to populate data from dao by parameter List (IN sql syntax).
populate data from dao per 100 list.