Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Split List into Smaller Lists.
This
example Splits the given big list to smaller
lists based
in Element Size.
/**
* The method returns List
of ArrayLists having 500 objects in each list.
* @param dataList the
dataList
*
@param numElements the num elements
* @return the
list[]
*/
public static List[]
splitArrayListIntoSmall(ArrayList dataList, int numElements)
{
if(dataList == null || dataList.size() == 0 || numElements ==
0)
return new List[0];
if(numElements < 0)
return (new List[] {
dataList
});
int numLists = (dataList.size() % numElements) ==
0?(dataList.size() /
numElements):((dataList.size() / numElements)+
1);
List result[] = new List[numLists];
for(int i = 0; i < numLists; i++)
{
int count = i + 1;
int fromIndex = Math.max((count - 1) * dataList.size()/numLists,
0);
int toIndex = Math.min(count * dataList.size()/numLists,
dataList.size());
result[i] = dataList.subList(fromIndex, toIndex);
}
return result;
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.