Sometimes, we need to export data from one system and import it into another system, and this data is very large, and the data import is restricted and cannot be implemented, then we need to do the dataListslicing, and then exporting, finally, the implementation of data import.
for the segmented processing of data, we can use the Sublist method to implement, the specific usage can be see the following cases:
Import java.util.ArrayList;
Import java.util.List;
public class Listtest {
public static void Main (string[] args) {
list<string> list = new arraylist<string> ();
List.add ("one");
List.add ("both");
List.add ("three");
List.add ("four");
List.add ("five");
List.add ("six");
List.add ("seven");
int ftest = 3;// data per fetch
int size = List.size ();
int temp = size/ftest + 1;
Boolean special = size% Ftest = = 0;
List<string> cutList = null;
for (int i = 0; i < temp; i++) {
if (i = = temp-1) {
if (special) {
Break
}
CutList = list.sublist (Ftest * i, size);
} else {
CutList = list.sublist (Ftest * I, ftest * (i + 1));
}
System.out.println (" No. " + (i + 1) + " Group:" + cutlist.tostring ());
}
}
}
The results are as follows:
Group 1 :[One, Two,three]
Group 2 :[Four, Five,six]
Group 3 :[seven]
if ftest = 1, the result is:
Group 1 :[One]
Group 2 :[ II ]
Group 3 :[three]
Group 4 :[four]
Group 5 :[Five]
Group 6 :[Six]
Group 7 :[seven]
The above is an example of its usage, can be combined with practical applications!
Java Common operations for list collections Beijing Java Basics