Java 8 Q&A | 🔥 Asked in Myntra | Find Nth Highest Salary Using Java Streams API | JavaTechie

Поділитися
Вставка
  • Опубліковано 2 жов 2024

КОМЕНТАРІ • 96

  • @purnasahu8766
    @purnasahu8766 Рік тому +21

    Excellent, plz bring such new types of java coding questions in your upcoming videos...

  • @tanson86
    @tanson86 Рік тому +4

    Nice incremental way of teaching streams in general.

  • @kshitijbansal3672
    @kshitijbansal3672 Рік тому +17

    Sir, I cant thank you more, today I had 2nd technical round with TechM, the interviewer asked the same question, that how you will group male and female on the basis of dept. but you are getting the Dept. name as a method argument. I randomly watched this video 3-4 days back and today when interviewer asked this question, I could only think about this video and provided him the solution in a minute.

    • @priyankaakhade5164
      @priyankaakhade5164 Рік тому +1

      Hi Kshitij,
      What would be the data format to group male and female on the basis of dept?

    • @JayeshKumar-i1r
      @JayeshKumar-i1r Місяць тому

      You have been placed?

  • @sajid.farooqi8074
    @sajid.farooqi8074 Рік тому +1

    Nice way of delivering such complicated looking problem.

  • @sagarjaiswal9451
    @sagarjaiswal9451 Рік тому +4

    Optional secondHighestEmployee = employees.stream()
    .collect(Collectors.groupingBy(Employee::getSalary, TreeMap::new, toList()))
    .entrySet()
    .stream()
    .skip(n-1)//
    .map(Map.Entry::getValue)
    .findFirst();
    System.out.println(secondHighestEmployee);

  • @ManojKumar-te5by
    @ManojKumar-te5by Рік тому +1

    Can you make an real example of Optional where use some frequent and important methods like OrElseGet() etc

  • @naincysharma5522
    @naincysharma5522 Рік тому

    Even if you cant...no worries..thanks for your efforts in making these videos that are of so much help

  • @sreetmi1918
    @sreetmi1918 11 місяців тому +3

    this is really good video for those who are lagging in doing programming with corejava.... if any one practice this and learn doing on their own..they ll start become stronger and stronger intheir coding skillls... thanks for the good work..

  • @charliegamboa9567
    @charliegamboa9567 Рік тому +4

    What a useful content and example. Thanks for sharing

  • @YogeshGhode-j5j
    @YogeshGhode-j5j 9 місяців тому +1

    Hi Sir why you have used "Collections.reverseOrder(Map.Entry.comparingByKey())" insted of "Comparator.comparing(Map.Entry.comparingByKey()).reversed()"

  • @sajid.farooqi8074
    @sajid.farooqi8074 Рік тому +2

    Hi please bring a complete tutorial on multi threading programing. As of no complete vedio tutorial i have found on UA-cam.

  • @sdash2023
    @sdash2023 Рік тому +2

    Sir I LRU and LFU cache using LinkedHashMap please. I failed epam interview because of LFU cache.

  • @user-0987-a
    @user-0987-a Рік тому +1

    Big thanks from Africa

  • @sandeep_begudem
    @sandeep_begudem 7 місяців тому +1

    for me remembering the entire syntax is tough. I don't know how would someone memorize the entire syntax and get the expected result LOL😇
    Thank you Basant for creating amazing content!

  • @chiranjib2patra
    @chiranjib2patra 5 місяців тому +1

    Thats a very good approach to teaching Basanth✌️ Liked it👍 Also would like to suggest if you could add a bigger display then the whole code we might get to see the single screen.

  • @beetc305shivsundarbankar9
    @beetc305shivsundarbankar9 Рік тому +1

    In output we got the map has key salary and value name, but if I want same map in which key is name and salary is value is it possible?

  • @kshitijbansal3672
    @kshitijbansal3672 Рік тому +3

    Sir, I cant thank you more, today I had 2nd technical round with TechM, the interviewer asked the same question, that how you will group male and female on the basis of dept. but you are getting the Dept. name as a method argument. I randomly watched this video 3-4 days back and today when interviewer asked this question, I could only think about this video and provided him the solution in a minute.

    • @Javatechie
      @Javatechie  Рік тому

      Glad to hear this buddy 🥰🥰. Keep learning 😃

    • @rushikeshgodase4150
      @rushikeshgodase4150 Рік тому

      Your experience. How much package they offered??

  • @bnayak8039
    @bnayak8039 7 місяців тому +1

    Hey thank you so much you deserve lasts of appreciation, but I expected not enough from you

  • @naincysharma5522
    @naincysharma5522 Рік тому +2

    Can you please help on a interview question where they asked to create a person class that has some fields like id, name, address, age etc and there can be 100+ such field in person class.
    We need to write a program to sort the person data using some dynamic criteria, like sample criteria can be
    Id only
    Id+ name
    Name onky
    Age onky
    Id+name+age
    And so on
    Can you help me on this..
    She suggested to use reflection api getdeclaredfield method and getproperty to solve yhis...which i cud not relate to

  • @siddharthagrawal4280
    @siddharthagrawal4280 Рік тому +2

    I have upcoming interview 2nd round on Friday. I know backend spring boot but am not aware of java 8 and all crucial features and usecases of it, i am told it will be asked for sure.
    Can you please suggest me few sources to understand everything about java 8 from scratch?? Or best make a small playlist if possible.
    Humble request! Could be Life changing for me!

    • @Javatechie
      @Javatechie  Рік тому

      It's already there please have a look
      ua-cam.com/play/PLVz2XdJiJQxzrdrpglCv_nWIO5CDIqOVj.html

    • @siddharthagrawal4280
      @siddharthagrawal4280 Рік тому +1

      Completed the playlist!
      It's pure Gem. Thanks man.

    • @raviravi-gg5ck
      @raviravi-gg5ck 9 місяців тому

      ​@@siddharthagrawal4280 u got selected ?

    • @siddharthagrawal4280
      @siddharthagrawal4280 9 місяців тому

      @@raviravi-gg5ck yes bro! This is great source for getting industry ready

  • @punyabikash3624
    @punyabikash3624 5 місяців тому

    Hello Sir, thank for this 👍👌 i have one question face by Cognizant that there is an array of integers he wanted out put as - { { 1,1,1,1},{2,1,1},{2,2},{3,1} } all possible combination of numbers whose sum is 4 if 4 is passed from console, if i pass 5 then all possible sum and so on could you help to make a video of it...plz

    • @Javatechie
      @Javatechie  5 місяців тому

      It's very simple you can try the approach below
      import java.util.stream.IntStream;
      public class NumberCombinationSum {
      public static void main(String[] args) {
      int targetSum = 10;
      findCombinations(targetSum);
      }
      public static void findCombinations(int targetSum) {
      IntStream.rangeClosed(1, targetSum / 2)
      .forEach(num1 -> {
      int num2 = targetSum - num1;
      System.out.println(num1 + " + " + num2 + " = " + targetSum);
      });
      }
      }

    • @punyabikash3624
      @punyabikash3624 5 місяців тому

      Thanks a lot for your Response :) :)
      this is not what he was expecting for example - i will pass 4 from console then output should be - { { 1,1,1,1},{2,1,1},{2,2},{3,1} }
      For example i will pass 5 then output should be - { { 1,1,1,1,1},{2,2,1},{3,2},{4,1} }
      For example i will pass 6 then output should be - { { 1,1,1,1,1,1},{2,2,2},{3,3},{4,2},{5,1} }

    • @Javatechie
      @Javatechie  5 місяців тому +1

      Ohh okay got it any combination. Will try and update you

  • @sumitsehgal8034
    @sumitsehgal8034 Рік тому +1

    Good one brother

  • @priyankapatil6783
    @priyankapatil6783 Місяць тому

    can you please try this find the largest word in a string in java

  • @muthulakshmisk5650
    @muthulakshmisk5650 Рік тому +1

    Hi bro.. ur videos are more clear. Are you working in software company?

    • @Javatechie
      @Javatechie  Рік тому

      Thank you buddy Yes i am a working employee in it

  • @suryaambati4880
    @suryaambati4880 Рік тому +1

    Hi ,I have list of employee objects I just want sort my employee list based on name in ascending order age in descending order ,salary in ascending order at a time
    How we make this combine sort ?

    • @Javatechie
      @Javatechie  Рік тому

      You need to customize your comparator. There is no direct support given by java 8

  • @hadouken99
    @hadouken99 Рік тому +1

    Thanks for good content. Hope you keep sharing on((:

  • @Aman-Thakor
    @Aman-Thakor Рік тому +1

    If I'm passing num value gt than size of sorted list, it will fail at get(index). What we can do in that case on streams?

    • @Javatechie
      @Javatechie  Рік тому +1

      Definitely it will fail, so you need to validate that num

  • @sourabh2635
    @sourabh2635 4 місяці тому

    Optionalsecodhighest=list.stream().sorted(Comparator.comparing(Employee::getSalary)).skip(3).findFirst();
    sysout(secondhghest) -- is this correct?

  • @vino7tech
    @vino7tech Рік тому +1

    Thank Your very Much sir. Many programmers are learn more knowledge by yours videos.

  • @pedurujagadish5048
    @pedurujagadish5048 Рік тому +1

    Bro realtime project implement action series chey bro

  • @gopisambasivarao5282
    @gopisambasivarao5282 Рік тому +1

    Thanks Basanth.Nice Video. God bless you.

  • @sudharsansathiamoorthy1075
    @sudharsansathiamoorthy1075 Рік тому +1

    Excellent tutorial Bro!! Please keep post solving new problems!!

  • @yatendra__singh
    @yatendra__singh Рік тому +2

    After watching these kind of videos from you ...i am just thinking how some one like you❤ got this much of depth knowledge in java ... could you please explain me in one word??

    • @PKKCAD
      @PKKCAD Рік тому

      May be he tried multiple times in offline.

    • @Javatechie
      @Javatechie  Рік тому +3

      I think the permanent hunger of learning helps everyone , thank you so much for your valuable words.

    • @Javatechie
      @Javatechie  Рік тому +3

      Of course Kk , i have tried it and understand the purpose of each line before preparing the video .

    • @sajid.farooqi8074
      @sajid.farooqi8074 Рік тому

      @@PKKCAD nothing is without practicing

  • @Suryanarayan094
    @Suryanarayan094 10 місяців тому +1

    We want more this kind of videos.

  • @bhavanisankar71
    @bhavanisankar71 Рік тому

    Sir please tell me how extract Text, table, images data from pdf using java. I am able to extracting text but remaining things how to get please tell me any solution

  • @abhishekgowlikar
    @abhishekgowlikar Рік тому +1

    Amazing videos for java techies.

  • @abasahebbhingardeve5464
    @abasahebbhingardeve5464 Рік тому

    Kindly make a video on fetching Arrey Index of top 4 records from millions of record in a database.

  • @Anilkumar-reddy
    @Anilkumar-reddy Рік тому +1

    Good video bro. Please make a more videos on java8 interview questions

    • @Javatechie
      @Javatechie  Рік тому

      Already uploaded buddy please search with keyword interview

  • @saurabhsuman4960
    @saurabhsuman4960 Рік тому +1

    Hello Sir, Nice content and thanks for detailed explanation. I have one question for sorting applied after grouping, Since the map key is Integer than shouldn't this apply sorting by default by using sort() method without passing Comparator implementation? I tried this but it failed and hence I thought to ask here
    ua-cam.com/video/eBDN04LlEOg/v-deo.html

    • @Javatechie
      @Javatechie  Рік тому +1

      Not getting you buddy could you please elaborate it little bit

    • @saurabhsuman4960
      @saurabhsuman4960 Рік тому +1

      @@Javatechie Apologies for confusion. I thought entry set can be sorted by using just sorted() method. It is clear that we need to pass Comparator for sorting of entry set.

    • @Javatechie
      @Javatechie  Рік тому +1

      Np

  • @krishnan6201
    @krishnan6201 11 місяців тому +1

    can you please make video on functional interface with recursive?

    • @Javatechie
      @Javatechie  11 місяців тому

      Recursive function class?

    • @krishnan6201
      @krishnan6201 11 місяців тому

      @@Javatechie No Recursive with lambda implementation any logic like factorial given number consider as example.

  • @immortalhuman7085
    @immortalhuman7085 Рік тому

    Can you make video on how to switch from service based company to product based company?

  • @DurgaShiva7574
    @DurgaShiva7574 Рік тому +1

    superb content

  • @mehedihassan5184
    @mehedihassan5184 Рік тому +1

    Thanks

  • @Thd369
    @Thd369 Рік тому +1

    Thank you

  • @pedurujagadish5048
    @pedurujagadish5048 Рік тому

    And also debugging process in realtime project chey bro series

    • @Javatechie
      @Javatechie  Рік тому

      Please check this link buddy ua-cam.com/video/Kon1DGwbtzg/v-deo.html

  • @bhargavi4557
    @bhargavi4557 11 місяців тому

    I was asked in a interview How to remove adjacent duplicates of a string in java8

    • @Javatechie
      @Javatechie  11 місяців тому

      Try below approach
      public static String removeAdjacentDuplicates(String input) {
      return input.chars()
      .mapToObj(c -> (char) c)
      .collect(StringBuilder::new, (sb, c) -> {
      if (sb.length() == 0 || sb.charAt(sb.length() - 1) != c) {
      sb.append(c);
      }
      }, StringBuilder::append)
      .toString();
      }

  • @srinath710
    @srinath710 Рік тому +1

    Good one ❤

  • @souvikc37
    @souvikc37 Рік тому +1

    Awesome 👍

  • @rishiraj2548
    @rishiraj2548 Рік тому +1

    🙏👍

  • @PrinceJeniFX
    @PrinceJeniFX 6 місяців тому

    How many years experience interview was this?

    • @Javatechie
      @Javatechie  6 місяців тому

      4+, but it can ask a fresher or even can ask to n+ experience

  • @shivAgar2020
    @shivAgar2020 Рік тому

    Experience ??

  • @RiskyRishy
    @RiskyRishy Рік тому

    great

  • @devkratos711
    @devkratos711 9 місяців тому

    👍

  • @rabisankarpodder7839
    @rabisankarpodder7839 Рік тому +1

    I have made it by the following way Employee nthHighestEmployee = employees.stream()
    .sorted(Comparator.comparingDouble(Employee::getSalary).reversed()).skip(n - 1).findFirst()
    .orElse(null);

    • @Javatechie
      @Javatechie  Рік тому

      If multiple employees have the same value will it work ?

    • @rabisankarpodder7839
      @rabisankarpodder7839 Рік тому

      @@Javatechie Yes it will take the previous value for 3rd highest salary. e.g . List employees = new ArrayList();
      employees.add(new Employee(101, "John", 5000));
      employees.add(new Employee(102, "Alice", 8000));
      employees.add(new Employee(103, "Bob", 3000));
      employees.add(new Employee(104, "Mary", 6000));
      employees.add(new Employee(105, "Tom", 2000));
      employees.add(new Employee(106, "Jane", 7000));
      employees.add(new Employee(108, "Rabi", 6000));
      employees.add(new Employee(107, "Mike", 4000)); Output:- Employee [empId=104, empName=Mary, salary=6000]

  • @66thakur99
    @66thakur99 Рік тому +1

    private static Entry getnthHighestSalaryEmployeeName(Map mappedWithSalary, Integer n) {
    return mappedWithSalary.entrySet().stream()
    .sorted(Collections.reverseOrder(Map.Entry.comparingByKey()))
    .skip(n - 1)
    .findFirst()
    .orElse(null);
    }

    • @Javatechie
      @Javatechie  Рік тому

      Execute this with different input there is a loop whole

  • @sarojsahoo8763
    @sarojsahoo8763 Рік тому +1

    Map dataMap = new HashMap();
    dataMap.put("Bharat",10000);
    dataMap.put("Ram",1200);
    dataMap.put("Laxman",1600);
    dataMap.put("Ravan",4500);
    dataMap.put("Lav",5230);
    Map.Entry nthHighest = dataMap.entrySet().stream()
    .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
    .skip(2)
    .findFirst()
    .get();
    System.out.println(nthHighest); //Can be done this way also

    • @nehasharma-lg3we
      @nehasharma-lg3we Рік тому

      It will not consider the case when two people have same salary I guess

    • @Javatechie
      @Javatechie  Рік тому +1

      Saroj yes if there will be more than 1 employee having the same salary it won't work