Java Sort | HackerRank Programming Solutions | HackerRank Java Solutions

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language Java . At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Java Sort-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To Java

JAVA was developed by James Gosling at Sun Microsystems Inc in the year 1991, later acquired by Oracle Corporation. It is a simple programming language. Java makes writing, compiling, and debugging programming easy. It helps to create reusable code and modular programs.

Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is similar to c/c++.

Link for the ProblemJava Sort- Hacker Rank Solution

Java Sort- Hacker Rank Solution

Problem :

You are given a list of student information: ID, FirstName, and CGPA. Your task is to rearrange them according to their CGPA in decreasing order. If two student have the same CGPA, then arrange them according to their first name in alphabetical order. If those two students also have the same first name, then order them according to their ID. No two students have the same ID.

Hint: You can use comparators to sort a list of objects. See the oracle docs to learn about comparators.

Input Format

The first line of input contains an integer , representing the total number of students. The next  lines contains a list of student information in the following structure:

ID Name CGPA

Constraints

The name contains only lowercase English letters. The  contains only integer numbers without leading zeros. The CGPA will contain, at most, 2 digits after the decimal point.

Output Format

After rearranging the students according to the above rules, print the first name of each student on a separate line

Sample Input

5
33 Rumpa 3.68
85 Ashis 3.85
56 Samiha 3.75
19 Samara 3.75
22 Fahim 3.76

Sample Output

Ashis
Fahim
Samara
Samiha
Rumpa
Java Sort- Hacker Rank Solution
import java.util.*;

class Student {
    private int id;
    private String fname;
    private double cgpa;

    public Student(int id, String fname, double cgpa) {
        super();
        this.id = id;
        this.fname = fname;
        this.cgpa = cgpa;
    }

    public int getId() {
        return id;
    }

    public String getFname() {
        return fname;
    }

    public double getCgpa() {
        return cgpa;
    }
}

public class Solution {
    
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int testCases = Integer.parseInt(in.nextLine());

        List<Student> studentList = new ArrayList<Student>();
        while (testCases-- > 0) {
            int id = in.nextInt();
            String fname = in.next();
            double cgpa = in.nextDouble();

            Student st = new Student(id, fname, cgpa);
            studentList.add(st);
        }
        Collections.sort(studentList, Comparator.comparing(Student::getCgpa).reversed().
                thenComparing(Student::getFname).thenComparing(Student::getId));
        for (Student st : studentList) {
            System.out.println(st.getFname());
        }
    }
}

680 thoughts on “Java Sort | HackerRank Programming Solutions | HackerRank Java Solutions”

  1. Hiya! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone 4. I’m trying to find a template or plugin that might be able to fix this issue. If you have any recommendations, please share. Appreciate it!

    Reply
  2. I haven’t checked in here for some time because I thought it was getting boring, but the last few posts are great quality so I guess I’ll add you back to my daily bloglist. You deserve it my friend 🙂

    Reply
  3. I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

    Reply
  4. Hello would you mind sharing which blog platform you’re using? I’m planning to start my own blog soon but I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S My apologies for being off-topic but I had to ask!

    Reply
  5. Hi , I do believe this is an excellent blog. I stumbled upon it on Yahoo , i will come back once again. Money and freedom is the best way to change, may you be rich and help other people.

    Reply
  6. I am curious to find out what blog platform you are working with? I’m experiencing some minor security issues with my latest site and I’d like to find something more safe. Do you have any recommendations?

    Reply
  7. Hello very nice site!! Guy .. Excellent .. Amazing .. I will bookmark your website and take the feeds alsoKI am happy to search out so many helpful information right here in the post, we need work out more strategies on this regard, thank you for sharing. . . . . .

    Reply
  8. A person necessarily help to make significantly articles I would state. This is the first time I frequented your web page and thus far? I amazed with the research you made to create this actual publish incredible. Great process!

    Reply
  9. I don’t even know how I ended up here, but I thought this post was good. I don’t know who you are but definitely you are going to a famous blogger if you are not already 😉 Cheers!

    Reply
  10. Hello! I’ve been following your web site for a long time now and finally got the bravery to go ahead and give you a shout out from Dallas Tx! Just wanted to tell you keep up the excellent job!

    Reply
  11. It’s really a nice and helpful piece of information. I’m glad that you simply shared this helpful info with us. Please stay us informed like this. Thanks for sharing.

    Reply
  12. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your website? My website is in the very same area of interest as yours and my visitors would definitely benefit from a lot of the information you present here. Please let me know if this okay with you. Appreciate it!

    Reply
  13. Have you ever thought about publishing an e-book or guest authoring on other websites? I have a blog centered on the same ideas you discuss and would really like to have you share some stories/information. I know my visitors would value your work. If you are even remotely interested, feel free to send me an e-mail.

    Reply
  14. Appreciating the commitment you put into your website and in depth information you provide. It’s awesome to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read! I’ve saved your site and I’m including your RSS feeds to my Google account.

    Reply
  15. I like the valuable information you provide in your articles. I will bookmark your weblog and check again here frequently. I am quite certain I will learn lots of new stuff right here! Good luck for the next!

    Reply
  16. Hi there would you mind stating which blog platform you’re working with? I’m looking to start my own blog in the near future but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something completely unique. P.S My apologies for getting off-topic but I had to ask!

    Reply
  17. Simply wish to say your article is as amazing. The clearness in your post is simply excellent and i can assume you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please continue the gratifying work.

    Reply
  18. An impressive share! I have just forwarded this onto a friend who was doing a little research on this. And he in fact bought me breakfast because I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending the time to discuss this matter here on your website.

    Reply
  19. Hey There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and come back to read more of your useful information. Thank you for the post. I will definitely comeback.

    Reply
  20. Greetings from Florida! I’m bored to tears at work so I decided to check out your site on my iphone during lunch break. I really like the knowledge you present here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, excellent site!

    Reply
  21. You really make it seem so easy with your presentation but I find this topic to be really something that I think I would never understand. It seems too complex and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

    Reply
  22. Good day! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results. If you know of any please share. Thank you!

    Reply
  23. canada pharmacy online [url=https://certifiedcanadapills.pro/#]canadian pharmacy antibiotics[/url] legitimate canadian mail order pharmacy

    Reply
  24. Hey there are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and create my own. Do you need any coding knowledge to make your own blog? Any help would be greatly appreciated!

    Reply
  25. Absolutely! Conclusion expos‚ portals in the UK can be overwhelming, but there are tons resources ready to cure you espy the unmatched the same as you. As I mentioned formerly, conducting an online search an eye to https://www.wellpleased.co.uk/wp-content/pages/what-happened-to-sam-brock-nbc-news-the-latest.html “UK hot item websites” or “British information portals” is a vast starting point. Not one desire this give you a thorough tip of communication websites, but it determination also provender you with a punter understanding of the in the air communication prospect in the UK.
    In the good old days you secure a file of potential rumour portals, it’s important to value each one to determine which overwhelm suits your preferences. As an exempli gratia, BBC Advice is known quest of its objective reporting of news stories, while The Keeper is known representing its in-depth opinion of partisan and social issues. The Unconnected is known championing its investigative journalism, while The Times is known in search its vocation and finance coverage. Not later than arrangement these differences, you can decide the information portal that caters to your interests and provides you with the newsflash you call for to read.
    Additionally, it’s quality looking at close by news portals for specific regions within the UK. These portals lay down coverage of events and news stories that are akin to the область, which can be firstly accommodating if you’re looking to hang on to up with events in your close by community. In place of occurrence, local news portals in London include the Evening Paradigm and the Londonist, while Manchester Evening Talk and Liverpool Repercussion are in demand in the North West.
    Blanket, there are tons tidings portals accessible in the UK, and it’s important to do your research to find the united that suits your needs. Sooner than evaluating the contrasting news portals based on their coverage, dash, and article angle, you can judge the individual that provides you with the most relevant and engrossing info stories. Good success rate with your search, and I hope this data helps you find the practised news portal since you!

    Reply
  26. Have you ever thought about creating an e-book or guest authoring on other sites? I have a blog centered on the same subjects you discuss and would really like to have you share some stories/information. I know my visitors would value your work. If you are even remotely interested, feel free to send me an e mail.

    Reply
  27. It is appropriate time to make a few plans for the longer term and it is time to be happy. I have read this publish and if I may just I want to recommend you few fascinating things or advice. Perhaps you could write next articles referring to this article. I wish to read more things approximately it!

    Reply
  28. Anna Berezina is a honoured inventor and demagogue in the deal with of psychology. With a background in clinical psychology and voluminous research experience, Anna has dedicated her career to understanding lenient behavior and unstable health: https://www.file-upload.com/yq2kuh6evkgd. Through her achievement, she has мейд important contributions to the battleground and has appropriate for a respected contemplating leader.

    Anna’s judgement spans several areas of feelings, including cognitive disturbed, unquestionable looney, and zealous intelligence. Her widespread knowledge in these domains allows her to victual valuable insights and strategies for individuals seeking in the flesh proliferation and well-being.

    As an inventor, Anna has written distinct instrumental books that drink garnered widespread recognition and praise. Her books tender mundane par‘nesis and evidence-based approaches to forbear individuals decoy fulfilling lives and develop resilient mindsets. By combining her clinical judgement with her passion on serving others, Anna’s writings secure resonated with readers all the world.

    Reply
  29. I simply could not depart your web site prior to suggesting that I extremely enjoyed the standard information a person supply on your visitors? Is going to be back frequently in order to check out new posts

    Reply
  30. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something enlightening to read?

    Reply
  31. Thank you for some other informative blog. Where else may just I am getting that kind of info written in such a perfect means? I have a project that I am simply now operating on, and I have been at the glance out for such information.

    Reply
  32. Have you ever thought about creating an e-book or guest authoring on other websites? I have a blog based upon on the same subjects you discuss and would really like to have you share some stories/information. I know my viewers would value your work. If you are even remotely interested, feel free to send me an e-mail.

    Reply
  33. Это лучшее онлайн-казино, где вы можете насладиться широким выбором игр и получить максимум удовольствия от игрового процесса.

    Reply
  34. Woah! I’m really loving the template/theme of this site. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say that you’ve done a amazing job with this. In addition, the blog loads extremely fast for me on Safari. Superb Blog!

    Reply
  35. where can i get doxycycline over the counter [url=https://doxycyclineotc.store/#]buy doxycycline over the counter[/url] doxycycline 20 mg tablets

    Reply
  36. Oh my goodness! Incredible article dude! Thank you, However I am encountering problems with your RSS. I don’t know why I can’t subscribe to it. Is there anyone else getting the same RSS problems? Anybody who knows the solution will you kindly respond? Thanx!!

    Reply
  37. Woah! I’m really loving the template/theme of this site. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between user friendliness and visual appearance. I must say you have done a very good job with this. In addition, the blog loads extremely fast for me on Internet explorer. Outstanding Blog!

    Reply
  38. Нужна стяжка пола в Москве, но вы не знаете, какой подрядчик лучше выбрать? Обратитесь к нам на сайт styazhka-pola24.ru! Мы предоставляем услуги по устройству стяжки пола любой площади и сложности, а также гарантируем качество и надежность.

    Reply
  39. Нужна механизированная штукатурка стен в Москве, но вы не знаете, как выбрать подрядчика? Обратитесь к нам на сайт mehanizirovannaya-shtukaturka-moscow.ru! Мы предлагаем услуги по машинной штукатурке стен любой площади и сложности, а также гарантируем доступные цены и высокое качество работ.

    Reply
  40. Mеханизированная штукатурка стен – это выбор современных людей. Узнайте больше на mehanizirovannaya-shtukaturka-moscow.ru.

    Reply
  41. Please let me know if you’re looking for a article writer for your weblog. You have some really great posts and I believe I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Many thanks!

    Reply
  42. Howdy! I realize this is kind of off-topic but I had to ask. Does operating a well-established blog like yours take a lot of work? I’m completely new to operating a blog but I do write in my diary daily. I’d like to start a blog so I can share my own experience and views online. Please let me know if you have any suggestions or tips for new aspiring bloggers. Appreciate it!

    Reply
  43. Hey! I know this is somewhat off topic but I was wondering which blog platform are you using for this site? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.

    Reply
  44. What i do not realize is actually how you’re not really a lot more well-favored than you may be right now. You are so intelligent. You know therefore significantly on the subject of this matter, produced me for my part believe it from so many various angles. Its like men and women don’t seem to be interested until it’s something to accomplish with Lady gaga! Your personal stuffs great. All the time deal with it up!

    Reply
  45. Hi there exceptional website! Does running a blog such as
    this take a massive amount work? I have no understanding
    of computer programming however I was hoping to
    start my own blog in the near future. Anyhow, should you have any ideas or techniques for new blog
    owners please share. I understand this is off subject nevertheless I just needed to ask.
    Many thanks!

    Reply
  46. Sight Care is a daily supplement proven in clinical trials and conclusive science to improve vision by nourishing the body from within. The Sight Care formula claims to reverse issues in eyesight, and every ingredient is completely natural.

    Reply
  47. Prostadine is a dietary supplement meticulously formulated to support prostate health, enhance bladder function, and promote overall urinary system well-being. Crafted from a blend of entirely natural ingredients, Prostadine draws upon a recent groundbreaking discovery by Harvard scientists. This discovery identified toxic minerals present in hard water as a key contributor to prostate issues.

    Reply
  48. GlucoBerry is one of the biggest all-natural dietary and biggest scientific breakthrough formulas ever in the health industry today. This is all because of its amazing high-quality cutting-edge formula that helps treat high blood sugar levels very naturally and effectively.

    Reply
  49. Introducing FlowForce Max, a solution designed with a single purpose: to provide men with an affordable and safe way to address BPH and other prostate concerns. Unlike many costly supplements or those with risky stimulants, we’ve crafted FlowForce Max with your well-being in mind. Don’t compromise your health or budget – choose FlowForce Max for effective prostate support today!

    Reply
  50. TropiSlim is a unique dietary supplement designed to address specific health concerns, primarily focusing on weight management and related issues in women, particularly those over the age of 40. TropiSlim targets a unique concept it refers to as the “menopause parasite” or K-40 compound, which is purported to be the root cause of several health problems, including unexplained weight gain, slow metabolism, and hormonal imbalances in this demographic.

    Reply
  51. Kerassentials are natural skin care products with ingredients such as vitamins and plants that help support good health and prevent the appearance of aging skin. They’re also 100% natural and safe to use. The manufacturer states that the product has no negative side effects and is safe to take on a daily basis. Kerassentials is a convenient, easy-to-use formula.

    Reply
  52. Bravo on the article! The content is insightful, and I’m curious if you plan to add more images in your upcoming pieces. It could enhance the overall reader experience.

    Reply
  53. EyeFortin is an all-natural eye-health supplement that helps to keep your eyes healthy even as you age. It prevents infections and detoxifies your eyes while also being stimulant-free. This makes it a great choice for those who are looking for a natural way to improve their eye health. https://eyefortinbuynow.us/

    Reply
  54. I was just seeking this info for a while. After six hours of continuous Googleing, at last I got it in your site. I wonder what is the lack of Google strategy that do not rank this type of informative sites in top of the list. Normally the top sites are full of garbage.

    Reply
  55. Hey there! I’ve been following your web site for a long time now and finally got the bravery to go ahead and give you a shout out from Porter Tx! Just wanted to tell you keep up the great job!

    Reply
  56. Hey There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and come back to read more of your useful information. Thank you for the post. I will definitely comeback.

    Reply
  57. I loved as much as you will receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an edginess over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this increase.

    Reply
  58. Its like you read my mind! You seem to know so much approximately this, like you wrote the book in it or something. I feel that you simply could do with some p.c. to drive the message house a bit, however other than that, this is great blog. A great read. I’ll definitely be back.