In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how JAVA tools divide a list into n lists. The quality of the article content is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
Requirements in Programming
Batch processing of a large piece of data: for example, from (Excel ,txt , database) line by line read data, finally read 1W + data, and then to this 1W + data and business processing, one by one traversal is too slow. You can split this large list into n, and then use n threads to run, so the efficiency will be much faster. The following code is one of the utility classes used in: Divide a List into n small lists
Detailed explanation of train of thought
A: A big list.
A small list of n.
Thinking: division like elementary school. 10/3=3 + 1. 10 pieces of data, divided into 3 lists, that each list is divided into 3 and 1 more, that only the first one is divided into 1 more, the first list is divided into 3 and then plus 1 remainder equals 4. The second list is divided into three, and then the last list is divided into three. The code is as follows, you can copy and run directly
solutions/**
* Divide a list into n lists.
* @param source
* @return
*/
public static List averageAssign(Listsource,intn){
List result=new ArrayList();
int remainder=source.size()%n; //calculate remainder first
int number=source.size()/n; //then quotient
int offset=0;//offset (used to identify the remainder of the addition)
for(int i=0;i0){
value=source.subList(i*number+offset, (i+1)*number+offset+1);
remainder--;
offset++;
}else{
value=source.subList(i*number+offset, (i+1)*number+offset);
}
result.add(value);
}
return result;
} About JAVA tools how to divide a list into n lists to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.