我現(xiàn)在在一個項目中遇到了一個問題,我只是為了了解更多關(guān)于 java 的信息,所以我有一個 txt 文件,它有奇跡,我必須閱讀它,然后將它的不同信息存儲在一個對象中( name country, heightdepth, accessibility, hostility, kmfromlondon, temperature, wondervalue and a fact about the wonder), then I have to sorting by the hostility rate 并輸出所有奇跡這是奇跡的txt文件:Amazonia,Brazil,60,10,10,8100,30,4,The Amazon rainforest occupies some 5.5 million square kilometres of South America.Iguassu Falls,Brazil|Argentina,82,11,50,10064,25,4,Two hundred and seventy waterfalls flow along nearly 3 kilometres of rivers.Niagra Falls,USA|Canada,50,18,69,5804,20,4,Adventurous tourists can take a cruise on the river below into the falls' mist.Giant's Causeway,Northern Ireland,12,19,17,592,15,2,Legend has it that is is a former 'walkway' to Scotland.Great Barrier Reef,Australia,60,10,10,15292,28,4,Over 30 species of whale and 15000 species of fish live here.Mount Everest,Tibet|Nepal,8840,7,95,7424,-10,4,The highest mountain on Earth is located in the Himalayas.Mount Vesuvius,Italy,1281,18,95,1630,30,1,The only volcano in mainland Europe to have erupted in the last 100 years.Old Faithful,USA,55,14,65,7432,118,2,Over half of the world's geysers are located in Yellowstone national park.Sahara Desert,African Union,3445,14,84,3800,35,3,Covers part of North Africa and is almost the same size as the USA.Great Rift Valley,African Union,1470,14,12,5887,25,4,The valley was formed by activity between tectonic plates 35 million years ago.Gobi Desert,Mongolia|China,2700,9,84,7279,30,3,The desert has been the location of many fossil finds.Ngorongoro Crater,Tanzania,610,14,19,5804,30,2,Home to almost 25000 animals including masses of flamingoes around Lake Magadi.Perito Morena Glacier,Argentina,60,9,82,13230,-5,3,The 5 kilometre wide glacier is well known for its process of rupturing.
1 回答

明月笑刀無情
TA貢獻(xiàn)1828條經(jīng)驗 獲得超4個贊
在 Java 中定義自定義排序的常規(guī)方法是通過Comparator實例。該對象可以插入到 egArrays
或的排序例程中Collections
。
例如,在 Java 8 中,您可以像這樣對數(shù)組進(jìn)行排序:
Arrays.sort(wonderArray,?Comparator.comparingInt(wonder?->?wonder.hospitality));
在 Java 7 或更早版本中,您可以使用匿名類來完成此操作:
Arrays.sort(wonderArray, new Comparator<Wonder>() {
? @Override public int compareTo(Wonder w1, Wonder w2) {
? ? return Integer.compare(w1.hospitality, w2.hospitality);
? }
});
添加回答
舉報
0/150
提交
取消