Lesson 33 of 34

Sorting, Comparator மற்றும் LambdasSorting, Comparators and Lambdas

10 min 35 XP

Collections.sort() எண்களையும் String-களையும் வரிசைப்படுத்தும். Objects-ஐ வரிசைப்படுத்த Comparator தேவை. Lambda (a, b) -> ... என்பது சிறிய method-ஐ ஒரே வரியில் எழுதும் வழி.

Collections.sort() sorts numbers and Strings. To sort objects you need a Comparator. A lambda like (a, b) -> ... writes a small method in one line.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Streams மூலம் filter, map போன்றவற்றை சுருக்கமாக எழுதலாம். Modern Java interviews-ல் இவை அடிக்கடி வரும்.

Streams let you filter and transform collections in a few words. Modern Java interviews ask about them often.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

n, பிறகு n வரிகளில் பெயர் மற்றும் மதிப்பெண் படியுங்கள். மதிப்பெண் அதிகமானவர் முதலில் வரும்படி வரிசைப்படுத்தி print செய்யுங்கள். மதிப்பெண் சமமாக இருந்தால் பெயர் அகர வரிசையில். Input: 3 Ram 80 Asha 95 Bala 80 Output: Asha 95 Bala 80 Ram 80

Read n, then n lines of name and score. Print them sorted by score, highest first; for equal scores, by name A to Z. Input: 3 Ram 80 Asha 95 Bala 80 Output: Asha 95 Bala 80 Ram 80

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.