Java 8 🔥 | Programming Interview Questions & Answers | Stream API | Java Techie

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 140

  • @gtbaba123
    @gtbaba123 Год назад +20

    Im springboot coder. Plz continue these series. Highly appreciated your work.

  • @muhassinmusthafa3379
    @muhassinmusthafa3379 Год назад +5

    Hi Bro..Thanks a lot..watched ur videos and really more helpful
    Two alternate ways to find the second highest number :
    Without using boxed()
    1. Integer secondHighest1 = Arrays.stream(num).sorted().skip(num.length - 2).findFirst().getAsInt();
    With using boxed()
    2. Optional secondHighest2 = Arrays.stream(num).boxed().sorted().skip(num.length - 2).findFirst();
    and then print secondHighest2.get()
    condition -> array should not be empty and must contain at least 2 elements

  • @thevagabond85yt
    @thevagabond85yt Год назад +3

    34:30 using map() is redundant
    List oneStartingNumberLists = Arrays.stream(nums)
    .boxed()
    .filter(n -> n.toString().startsWith("1"))
    .collect(Collectors.toList());
    Since it is boxed() meaning Integer can be converted into string using toString()

  • @abiz504
    @abiz504 8 месяцев назад +4

    Thanks @javatechie excellent content, but for this problem, this is much simpler //find longest string from given array
    String longestword = strings.stream().max((s1,s2)->s1.length()-s2.length()).get();

  • @amolorape13
    @amolorape13 Год назад +12

    Because of you sir i cracked couple interviews, when I started looking for a new job, I just watching your video again and revising the concept
    One of the best RUclips channel for learner
    Lot's of respect sir..

    • @Javatechie
      @Javatechie  Год назад

      Glad to hear this Amol 😍. Congratulations for your achievements and keep learning 😃

  • @ksaravind9739
    @ksaravind9739 Год назад +2

    very very good and useful bro, this is called spoon feeding 😄😍😍😍 love it

  • @manishamahapatro4916
    @manishamahapatro4916 20 часов назад +1

    thank you so much Sir for providing such knowledge for free😇

  • @chandan07talreja
    @chandan07talreja Год назад +2

    Excellent Video Basant. Keep Interviews Videos like this coming.

  • @sidhanshuraghuvanshi1
    @sidhanshuraghuvanshi1 11 месяцев назад +1

    Most Interviewed questions on Stream APIs. Best channel out there as I said earlier also. Keep doing this great work man. Thanks a lot❤

  • @aadiraj6126
    @aadiraj6126 Год назад +19

    Very useful lecture for beginners. Produce more such interview related coding questions which involves 0 to 6/7 years. We're here to consume 😋

  • @AkshaySingh-wx3cp
    @AkshaySingh-wx3cp 10 месяцев назад +1

    It's just perfect. Thank you. Please keep going.

  • @azimahmad5007
    @azimahmad5007 2 месяца назад +2

    Great Explanation Sir, Thank you so much!

  • @soulfulGirl_
    @soulfulGirl_ Год назад +2

    Your really doing amazing job, with no doubt about content I can trust n watch and get quality content , thank you and please continue doing this great job.😊

  • @saurabhsuman4960
    @saurabhsuman4960 Год назад +1

    Simple and to the point coverage of different stream related questions. Thanks for your efforts.

  • @Atul_Shegokar
    @Atul_Shegokar Год назад +1

    wow excellent.... Thank you very much @Java Techie, many times asked this questions & now I can answer.

  • @vinodnayak27
    @vinodnayak27 Год назад +2

    Really Useful and covered most of the repeatated questions on Java 8 interviews...Thanks Basant😍

  • @mohammadzakaria2579
    @mohammadzakaria2579 Год назад +3

    Great Video 🙌Thanks for sharing 👍
    Please keep sharing similar coding challenges on Java8+

  • @dmode1535
    @dmode1535 Год назад +2

    Thanks, just what I needed for my upcoming interview.

  • @claytonrobert3907
    @claytonrobert3907 8 месяцев назад +1

    Best ever java coding stream 8 video .

  • @pravaskumar7078
    @pravaskumar7078 Год назад +1

    Ur content are always unique , Very Helpful set of Question and answers

  • @aman_deep21
    @aman_deep21 Год назад +1

    thank you for teaching how to use stream API effectively

  • @farhaankazi7134
    @farhaankazi7134 5 месяцев назад +1

    Awesome video, specially how he showed groupingBy() example and trick to solve many interview questions using this base technique where cosmetic modifications do wonders. The other thing is that he shown one example second largest/lowest and largest/lowest element in list but there is one additional thing is required which is to add distinct() keyword in stream otherwise if there are duplicate largest/lowest number then it would not work

    • @Javatechie
      @Javatechie  5 месяцев назад

      Thanks buddy 😀. Yes distinct is required you are right

  • @abhinavmishra9690
    @abhinavmishra9690 Год назад +1

    Very informative and useful video for interview. Thanks

  • @vino7tech
    @vino7tech Год назад +1

    really it is great video for clear the interview and getting more knowledge by way of your teaching . Thank you very much sir.

  • @anilreddy5291
    @anilreddy5291 Год назад +1

    I am waiting from long time. Thanks

  • @SipunsOriginal
    @SipunsOriginal Год назад +1

    Nice one quick recall before the interview.

  • @ishantkhandelwal6263
    @ishantkhandelwal6263 Год назад +4

    Excellent ! Please bring in some more practical problem solving examples in JAVA. This is very rare high quality stuff

    • @Javatechie
      @Javatechie  Год назад

      Thanks buddy i will

    • @arnabchowdhury4892
      @arnabchowdhury4892 Год назад

      ​@@Javatechie Please create a java 8 code to find sub string with maximum repeating characters

  • @yogeshpatil-vx2pi
    @yogeshpatil-vx2pi Год назад +3

    That’s very well covered . 👏one request Basant if u can create videos on Microservices interview questions in detailed with examples will be helpful for many of us . Thanks for all work you are doing so far ❤🎉

    • @Javatechie
      @Javatechie  Год назад +1

      Yes buddy it's in a queue. Will upload within a month

    • @malleswarrao3887
      @malleswarrao3887 Год назад +2

      ​@@Javatechieyes we are waiting

  • @techtips7641
    @techtips7641 Год назад +1

    Please provide more examples.. It really helps!!.. Continue doing this as a series.. thanks a lot

  • @phanimadhuri4087
    @phanimadhuri4087 7 месяцев назад

    Good video.very useful for coding interviews.

  • @Rashminaresh-j3j
    @Rashminaresh-j3j Год назад +1

    Very informative and helpful

  • @vishalmore5653
    @vishalmore5653 Год назад +1

    Hi Sir, This video is very much useful. please make such video more frequent. 🙏

  • @azharnawaz1020
    @azharnawaz1020 Год назад +1

    my guruji is always the best🙏🙏🙏

  • @shekhar1497
    @shekhar1497 Год назад +1

    thank you very useful lecture.

  • @jagrutipatil1020
    @jagrutipatil1020 Год назад +1

    Appreciated 😊🙏

  • @neerajayarasani8456
    @neerajayarasani8456 Год назад

    Simply Great video brother, Thank you

  • @JensonCruz-t8j
    @JensonCruz-t8j Месяц назад +1

    21:10 As we're using an optional class can we use it like below
    String firstNonRepeat= Arrays.stream(name.split(""))
    .collect(Collectors.groupingBy(Function.identity(),LinkedHashMap::new,Collectors.counting()))
    .entrySet().stream()
    .filter(t -> t.getValue()==1)
    .map(Map.Entry::getKey)
    .findFirst()
    .orElse("No such element found");

    • @durgaprasad1368
      @durgaprasad1368 Месяц назад +1

      Yes , when we use findFirst() it returns an optional container so we can use the orElse method.

  • @jaswantshergill8357
    @jaswantshergill8357 9 месяцев назад +1

    Very informative video

  • @vivekpal7865
    @vivekpal7865 3 месяца назад +2

    simple solution for finding nth largest string .String longestStrList=Arrays.stream(str1)
    .sorted((s1, s2) -> s2.length() - s1.length())
    .skip(n-1)
    .findFirst()
    .orElse("");

    • @Javatechie
      @Javatechie  3 месяца назад

      Awesome man let me try this .

  • @nirmesh44
    @nirmesh44 Год назад +1

    superb explanation.

  • @sarojsahoo8763
    @sarojsahoo8763 Год назад +1

    Very nice explained

  • @Vithal_Nivargi
    @Vithal_Nivargi Год назад +1

    Thanks 👍 please make one more videos on coding questions

  • @tveshamahanta1300
    @tveshamahanta1300 Год назад

    Very useful video 🙏please make more videos!

  • @babyRishabh_littleWorld
    @babyRishabh_littleWorld Год назад +1

    Thank You Java Techie 😊

  • @maankhurana5814
    @maankhurana5814 6 месяцев назад +2

    Need more such coding videos ... coz most of the people only uploading theory videos not practical .

  • @sakshibhisikar2547
    @sakshibhisikar2547 9 месяцев назад

    Thanks for this video ❤

  • @fookoboy9623
    @fookoboy9623 Год назад +1

    very useful sir

  • @alokkottawar9394
    @alokkottawar9394 Год назад

    Informatic session

  • @archie5766
    @archie5766 Год назад +1

    hey stream dont use your brain and use hashmap...listen to basant sir :) explaining with humor really nice sir. Thanks

  • @vrushabhpawar4209
    @vrushabhpawar4209 Год назад +1

    Hi @Javatechie, in 3rd question for finding 1st non repeat element from the String, if we provide new LinkedHashMap() instead of LinkedHashMap constructor refferance its giving compilation error, Do u know why?

    • @Javatechie
      @Javatechie  Год назад +1

      No we need to give a new object of LinkedIn hashmap . Pass as constructor or method reference it's upto you

  • @jaswanthreddy8749
    @jaswanthreddy8749 Год назад +3

    Hello Basant,
    For unique elements we can use distinct() method function also right, correct me If I am wrong thinking.
    String name = "ILoveJavaTechie";
    String[] split1 = name.split("");
    Stream distinct = Arrays.stream(split1).distinct();
    System.out.println("FoundDuplicate elements " + "" + distinct.collect(Collectors.toList()));

    • @Javatechie
      @Javatechie  Год назад

      This will give you a unique element not duplicate

  • @tanveerkundargi5249
    @tanveerkundargi5249 9 месяцев назад

    really helpful, thank you

  • @Rkreddy123
    @Rkreddy123 Год назад +1

    Very useful

  • @sdash2023
    @sdash2023 Год назад +2

    Sir they are saying not to use .Get() for optionals in reactive programs. Could u plz say whats the best way to handle optopnals in reactive way? ❤ you sir.

    • @Javatechie
      @Javatechie  Год назад +2

      Check isEmpty or offNullable in optional then get the object that is the correct way to deal with optional

    • @sdash2023
      @sdash2023 Год назад +1

      @@Javatechie thanks a lot sir.

  • @satishp351
    @satishp351 Год назад +1

    good video

  • @uvanana.
    @uvanana. 9 месяцев назад +1

    Thanks 😊

  • @radhikagadve
    @radhikagadve Год назад +1

    Max length str solution ----> Arrays.asList(strArray).stream().max(Comparator.comparing(String::length)).get();

  • @AdvaitK-kw4sb
    @AdvaitK-kw4sb 8 месяцев назад +1

    Great Video !! Very well explain each answer. Where can we find the source code,am not able to see in git repo

    • @Javatechie
      @Javatechie  8 месяцев назад

      GitHub link mentioned in the video description

  • @akashtawade9264
    @akashtawade9264 Год назад +2

    For second highest number program,
    if
    int[] numbers = {5,9,11,2,8,21,21,1};
    Then your logic will fail because...in reverse order it will show [21,21,11,9,8,5,1].....but second highest number is 11....but it will show 21.
    I think we need to add one more logic for remove duplicacy again then only it will show 11.
    int[] numbers = {5,9,11,2,8,21,21,1};
    Integer SecondHighestElement = Arrays.stream(numbers).boxed()
    .collect(Collectors.toSet()).stream()
    .sorted(Comparator.reverseOrder())
    .skip(1)
    .findFirst()
    .get();
    System.out.println(SecondHighestElement);
    This will work.
    @Javatechie

  • @praveens2272
    @praveens2272 Год назад +1

    Thanks Basant

  • @icode24x7
    @icode24x7 Год назад

    Nice Video..!!...Appreciate if you can you please create a playlist of Java where time complexity and space complexity is maintained.

  • @garikinarajesh1999
    @garikinarajesh1999 Год назад +2

    How you are exploring these methods. What strategy you will use while exploring any new technology.

    • @oludamilareolukotun9929
      @oludamilareolukotun9929 Год назад +3

      In my opinion documentation and there are also good books out there

    • @Javatechie
      @Javatechie  Год назад +3

      Practice a few more basic programs and then try to convert it to java 8 stream and play with it .
      You will explore more and more once you start playing with it .
      To be fair i don't use documentation to learn rather i tried to understand various scenarios by debugging source code

  • @Blaze_Killer
    @Blaze_Killer 7 месяцев назад

    THANK YOU SO MUCH

  • @vasu5313
    @vasu5313 Год назад

    Second Highest, why cant be this... 25:00
    Integer res = Arrays.stream(numbers).boxed().sorted().collect(Collectors.toList()).get(numbers.length - 2);
    Yes but your solution can handle exception FindFirst :)

    • @bhargavchowdary6363
      @bhargavchowdary6363 Месяц назад

      Because we don't need to collect to the list
      As well as we can return default value like orelse

  • @bhargavchowdary6363
    @bhargavchowdary6363 Месяц назад

    The purpose of boxed is not autoboxing
    It just converts IntStream to Stream

  • @neha6000
    @neha6000 Год назад +1

    Wow thanks

  • @sayantanghosh5939
    @sayantanghosh5939 Год назад +2

    Please continue the Kafka series .eagerly waiting for that .

    • @Javatechie
      @Javatechie  Год назад +3

      Yes buddy next weekend i will upload 2 videos on Kafka.

    • @sayantanghosh5939
      @sayantanghosh5939 Год назад +1

      @@Javatechie please complete the series . Waiting since long for your Kafka series .❤️

  • @tejeswarreddytadi3289
    @tejeswarreddytadi3289 Год назад +1

    Will these be asked for 5 years candidate. Please share as well some other questions as well basant, thank you ❤❤❤ to your channel

    • @Javatechie
      @Javatechie  Год назад

      Yes buddy programming questions is common for any experience

  • @_itbuddy
    @_itbuddy Год назад +2

    Sir please make video on checkmarks for intellij

  • @paramaguruo5302
    @paramaguruo5302 Год назад +1

    How to find unique elements from 2 different list of integers. Element in one list should not present in other list. Request you to share the program to solve the above problem. Thanks

    • @Javatechie
      @Javatechie  Год назад

      Please share some sample inputs

  • @AjaySingh-mo6ho
    @AjaySingh-mo6ho 9 месяцев назад

    if Array like this- Integer arr[] = {10, 5, 8, 22, 30, 30, 2}; then how to find second largest element of this array?

  • @nikhilgobade297
    @nikhilgobade297 Год назад +1

    1st question was asked to me in TechMahindra interview.

    • @Farm2Code
      @Farm2Code 9 месяцев назад

      For what much experience

  • @akashtawade9264
    @akashtawade9264 Год назад +1

    For Duplicate elements, we can use Collections.frequency(1,x)....By using this we can easily filter out duplicate.
    Then why you took map and all ?
    String s=input.toLowerCase();
    char ch[]= s.toCharArray();
    List list = new ArrayList();
    for(char c:ch)
    {
    list.add(c);
    }
    list.stream().filter(t->Collections.frequency(1,x)>1).collect(Collectors.toList()).forEach(System.out::println);
    @Javatechie

  • @jeebanpradhan8050
    @jeebanpradhan8050 Год назад

    Bro why did u take entryset here ?

  • @jeebanpradhan8050
    @jeebanpradhan8050 Год назад

    What is identity method use case of plz ??

  • @rishiraj2548
    @rishiraj2548 Год назад +1

    🙏💯💯

  • @arnabchowdhury4892
    @arnabchowdhury4892 Год назад

    ​ @Javatechie
    Please create a java 8 code to find sub string with maximum repeating characters

  • @sasmitamohanty4536
    @sasmitamohanty4536 Год назад +1

    Please make videos on Apache Kafka

    • @Javatechie
      @Javatechie  Год назад

      Please check out my Kafka playlist

  • @Kannayyaedits
    @Kannayyaedits Год назад

    How to find missing numbers in array using streams ?

  • @michaeldeng1981
    @michaeldeng1981 Год назад +1

    Hi, java 20 just released

  • @bhavanisankar71
    @bhavanisankar71 Год назад

    Thanks brother first question I faced in interview that time I failed to write 😔 ,do next video for core java when we go for java 8, because in system round they are asking time complexity and memory wasting , so which one is best loops or java8

    • @oludamilareolukotun9929
      @oludamilareolukotun9929 Год назад +1

      Functional programming does not improve the performance of any system. it has the same complexity as writing a conventional imperative style of programming. The only advantage streams and functional programming generally present is, clean, concise and easy to read code.

    • @bhavanisankar71
      @bhavanisankar71 Год назад

      @@oludamilareolukotun9929 which one best

    • @oludamilareolukotun9929
      @oludamilareolukotun9929 Год назад +4

      @@bhavanisankar71 Functional style is better. Take a look at the 2 styles for removing duplicate below. You will see functional is easy to read and clean
      FOR LOOP FOR GETTING DUPLICATE
      public static List getDuplicateForLoopStyle(List strings){
      Map maps = new HashMap();
      for (String s : strings){
      if (!maps.isEmpty() && maps.containsKey(s)){
      int value = maps.get(s);
      maps.put(s,++value);
      }else maps.put(s,1);
      }
      List result = new ArrayList();
      for (Map.Entry entry : maps.entrySet()){
      if (entry.getValue() > 1){
      result.add(entry.getKey());
      }
      }
      return result;
      }
      FUNCTIONAL STYLE FOR GETTING DUPLICATE
      public static List getDuplicateFunctionalStyle(List strings){
      return strings.stream()
      .collect(Collectors.groupingBy(x -> x, Collectors.counting()))
      .entrySet()
      .stream()
      .filter(x -> x.getValue() > 1)
      .map(Map.Entry::getKey)
      .collect(Collectors.toList());
      }

  • @jeebanpradhan8050
    @jeebanpradhan8050 Год назад

    Bro how l is first non rpt .. bcoz c is non repeat first

  • @rishiraj2548
    @rishiraj2548 Год назад +1

    Good day

  • @azharnawaz1020
    @azharnawaz1020 Год назад +1

    guruji please do one real time project guruji please so that we can survive in industry

  • @karthiyayeni1
    @karthiyayeni1 6 месяцев назад +1

    Second question find duplicate elements from a string
    List strList = Arrays.asList(result);
    List dupElements = strList.stream().filter(e->Collections.frequency(strList, e)>1).distinct().collect(Collectors.toList());
    System.out.println(dupElements);

  • @bhargavi4557
    @bhargavi4557 Год назад +1

    How to remove adjacent duplicates of a string in java8

    • @Javatechie
      @Javatechie  Год назад

      Try this
      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();
      }

    • @bhargavi4557
      @bhargavi4557 Год назад

      @@Javatechie thank you for your response

  • @jeebanpradhan8050
    @jeebanpradhan8050 Год назад

    Bro groupby simple definition plz

  • @RealSlimShady-um6gf
    @RealSlimShady-um6gf Год назад +1

    Latest versions of Java please.

  • @johnvick8861
    @johnvick8861 Год назад

    i want use of redis

  • @TechInfo1663
    @TechInfo1663 Год назад

    String input= a2b2c1d3,
    String output=aabbcddd
    Anybody implement it

    • @Javatechie
      @Javatechie  Год назад

      You can achieve this using Java 8 streams. Here's a Java program that takes the input "a2b2c1d3" and produces the output "aabbcddd" using streams:
      ```java
      import java.util.stream.Collectors;
      public class Main {
      public static void main(String[] args) {
      String input = "a2b2c1d3";
      String output = decodeString(input);
      System.out.println(output);
      }
      public static String decodeString(String input) {
      return input.chars()
      .mapToObj(c -> (char) c)
      .collect(StringBuilder::new, (sb, c) -> {
      if (Character.isLetter(c)) {
      sb.append(c);
      }
      if (Character.isDigit(c)) {
      int count = Character.getNumericValue(c);
      char prevChar = sb.charAt(sb.length() - 1);
      for (int i = 0; i < count - 1; i++) {
      sb.append(prevChar);
      }
      }
      }, StringBuilder::append)
      .toString();
      }
      }
      ```
      This program uses streams to process the input string character by character and builds the desired output. When you run it with the input "a2b2c1d3," it will produce the output "aabbcddd."

  • @CheeseStickzZ
    @CheeseStickzZ Год назад

    That's a nice explanation for java 8, but the exercises you are solving, best way is not to do them with streams, just a regular for loop

    • @oludamilareolukotun9929
      @oludamilareolukotun9929 Год назад

      why not stream?

    • @CheeseStickzZ
      @CheeseStickzZ Год назад +1

      @@oludamilareolukotun9929 it's slower with streams unless you have a very large dataset in the array, like 1,000 elements, otherwise for loop and just using collections is faster performance

    • @debiprasaddash654
      @debiprasaddash654 Год назад

      Then why companies are still using java8

  • @coderbaba786
    @coderbaba786 Год назад +1

    Hi All, Integer l = Arrays.asList(1, 41, 3, 31, 1).stream()
    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).entrySet().stream()
    .filter(x -> x.getValue() == 1l).findFirst().get().getKey();
    System.out.println(l);
    In this example I am expecting output 41 but getting 3 , why ?? ?????/

    • @Javatechie
      @Javatechie  Год назад +1

      It will internally use a hashmap so we can't expect an insertion order . That's why I explained in video what to do check and apply

  • @Ali-k6k3b
    @Ali-k6k3b Год назад +1

    very helpful