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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

ความคิดเห็น • 96

  • @purnasahu8766
    @purnasahu8766 ปีที่แล้ว +21

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

  • @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 TH-cam.

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Okay buddy i will

  • @gopisambasivarao5282
    @gopisambasivarao5282 ปีที่แล้ว +1

    Thanks Basanth.Nice Video. God bless you.

  • @YogeshGhode-j5j
    @YogeshGhode-j5j 8 หลายเดือนก่อน +1

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

  • @Suryanarayan094
    @Suryanarayan094 10 หลายเดือนก่อน +1

    We want more this kind of videos.

  • @sourabh2635
    @sourabh2635 4 หลายเดือนก่อน

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

  • @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?

  • @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

  • @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

  • @shivAgar2020
    @shivAgar2020 ปีที่แล้ว

    Experience ??

  • @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..

  • @sdash2023
    @sdash2023 ปีที่แล้ว +2

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

    • @Javatechie
      @Javatechie  ปีที่แล้ว +1

      Okay i will

    • @sdash2023
      @sdash2023 ปีที่แล้ว

      @@Javatechie thank you Sir.

  • @charliegamboa9567
    @charliegamboa9567 ปีที่แล้ว +4

    What a useful content and example. Thanks for sharing

  • @tanson86
    @tanson86 ปีที่แล้ว +4

    Nice incremental way of teaching streams in general.

  • @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.

  • @sandeep_begudem
    @sandeep_begudem 6 หลายเดือนก่อน +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!

  • @priyankapatil6783
    @priyankapatil6783 หลายเดือนก่อน

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

  • @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??

  • @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

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Sure i will check this buddy. Quite interesting

    • @naincysharma5522
      @naincysharma5522 ปีที่แล้ว

      @@Javatechie thank you so much!!

  • @bnayak8039
    @bnayak8039 7 หลายเดือนก่อน +1

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

  • @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?

  • @ManojKumar-te5by
    @ManojKumar-te5by ปีที่แล้ว +1

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

  • @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

  • @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);

    • @Krishnadevaraya1
      @Krishnadevaraya1 4 หลายเดือนก่อน

      Employees is a list or map

  • @sajid.farooqi8074
    @sajid.farooqi8074 ปีที่แล้ว +1

    Nice way of delivering such complicated looking problem.

  • @vino7tech
    @vino7tech ปีที่แล้ว +1

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

  • @hadouken99
    @hadouken99 ปีที่แล้ว +1

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

  • @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
      th-cam.com/play/PLVz2XdJiJQxzrdrpglCv_nWIO5CDIqOVj.html

    • @siddharthagrawal4280
      @siddharthagrawal4280 ปีที่แล้ว +1

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

    • @raviravi-gg5ck
      @raviravi-gg5ck 8 หลายเดือนก่อน

      ​@@siddharthagrawal4280 u got selected ?

    • @siddharthagrawal4280
      @siddharthagrawal4280 8 หลายเดือนก่อน

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

  • @pedurujagadish5048
    @pedurujagadish5048 ปีที่แล้ว +1

    Bro realtime project implement action series chey bro

  • @sudharsansathiamoorthy1075
    @sudharsansathiamoorthy1075 ปีที่แล้ว +1

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

  • @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

  • @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

  • @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

  • @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

  • @abhishekgowlikar
    @abhishekgowlikar ปีที่แล้ว +1

    Amazing videos for java techies.

  • @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

  • @user-0987-a
    @user-0987-a ปีที่แล้ว +1

    Big thanks from Africa

  • @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
    th-cam.com/video/eBDN04LlEOg/w-d-xo.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

  • @abasahebbhingardeve5464
    @abasahebbhingardeve5464 ปีที่แล้ว

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

  • @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.

  • @sumitsehgal8034
    @sumitsehgal8034 ปีที่แล้ว +1

    Good one brother

  • @DurgaShiva7574
    @DurgaShiva7574 ปีที่แล้ว +1

    superb content

  • @immortalhuman7085
    @immortalhuman7085 ปีที่แล้ว

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

  • @Thd369
    @Thd369 ปีที่แล้ว +1

    Thank you

  • @mehedihassan5184
    @mehedihassan5184 ปีที่แล้ว +1

    Thanks

  • @srinath710
    @srinath710 ปีที่แล้ว +1

    Good one ❤

  • @souvikc37
    @souvikc37 ปีที่แล้ว +1

    Awesome 👍

  • @rishiraj2548
    @rishiraj2548 ปีที่แล้ว +1

    🙏👍

  • @naincysharma5522
    @naincysharma5522 ปีที่แล้ว

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

  • @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();
      }

  • @pedurujagadish5048
    @pedurujagadish5048 ปีที่แล้ว

    And also debugging process in realtime project chey bro series

    • @Javatechie
      @Javatechie  ปีที่แล้ว

      Please check this link buddy th-cam.com/video/Kon1DGwbtzg/w-d-xo.html

  • @devkratos711
    @devkratos711 9 หลายเดือนก่อน

    👍

  • @RiskyRishy
    @RiskyRishy ปีที่แล้ว

    great

  • @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