मुझे स्ट्रीम से एक सूची क्रमबद्ध करने में दिलचस्पी है। यह वह कोड है जिसका मैं उपयोग कर रहा हूं:जावा में stream.sorted() के साथ एक सूची को सॉर्ट करना
list.stream()
.sorted((o1, o2)->o1.getItem().getValue().compareTo(o2.getItem().getValue()))
.collect(Collectors.toList());
क्या मुझे कुछ याद आ रही है? सूची क्रमबद्ध नहीं है।
इसे आइटम के अनुसार सबसे कम मूल्य वाले सूचियों को सॉर्ट करना चाहिए।
for (int i = 0; i < list.size(); i++)
{
System.out.println("list " + (i+1));
print(list, i);
}
और प्रिंट विधि:
public static void print(List<List> list, int i)
{
System.out.println(list.get(i).getItem().getValue());
}