In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to sort two arrays with Java". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to sort two arrays with Java".
Suppose you have number,group, two arrays whose elements are numbers, and now the rules to sort them are as follows:
1. If the element in group exists in numbers,
two。 To put the numbers that appear in group before those in number, pay attention to sorting
Numbers = [8, 3, 1, 2, 5, 4, 4, 7] group = {2, 3, 3, 5, 5, 7}
After analysis, it should be a matter of priority, and the method of tuple sorting is used here:
Numbers = [8, 3, 1, 2, 5 Magazine 4 7 Magazine 6] group = {2 Magne3 Magazine 5 7} tmp = [] for x in numbers: if x in group: tmp.append ((0, x)) else: tmp.append ((1, x)) tmp.sort () print (list (map (lambda XRX [1], tmp)
I saw a classic code on the Internet:
Def sort_priority (values,group): def helper (x): if x in group: return (0, x) return (1, x) values.sort (key=helper) numbers = [8,3,1,2,5 sort_priority (numbers, group) print (numbers)
Recommend the method of using the second higher order function
Thank you for your reading, the above is the content of "how to sort two arrays with Java". After the study of this article, I believe you have a deeper understanding of how to sort two arrays with Java. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.