In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to achieve Java List does not repeatedly extract Util", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to achieve Java List without repeated extraction of Util"!
Import java.util.ArrayList;import java.util.List;import java.util.Random / * @ Author: wuyiqi * @ Date: 2021-03-16 10:17 * @ Description: universal list extraction does not repeat * / public class ExtractUtil {/ * batch extraction * @ param size extraction * @ list of param records extraction * @ param type * @ return * / public static List extractList (int size, List records) {int total = records.size (); if (total
< 1 || size < 1) { return null; } if (size >= total) {return records;} / / if the percentage extracted is greater than 50%, extract what is not needed, and then reverse boolean reverse = false; if ((double) size / total > 0.5) {reverse = true; size = total-size;} / / extract the core method List list = new ArrayList (); for (int I = 0 I
< size; i++) { int random = new Random().nextInt(total); T t = extract(random, list, records); if (null != t) { list.add(t); } } // 如果反转 if (reverse) { List temp = new ArrayList(); for (T record : records) {if (!list.contains(record)) { temp.add(record); } } list = temp; } return list; } /** * 单个抽取;不重复抽取 * @param index 抽取位置 * @param newList 抽中的列表 * @param records 抽取的列表 * @param 类型 * @return */ public static T extract(int index, List newList, List records) { int total = records.size(); if (total < 1 || index >= total) {return null;} T t = records.get (index); if (newList.contains (t)) {t = extract (new Random (). NextInt (total), newList, records);} return t;}} so far, I believe you have a deeper understanding of "how to achieve Java List without repeatedly extracting Util". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.