Java Coding Questions Asked in Mastercard Interview
JAVA INTERVIEW BUDDY · 5,849 words · 29 min read · EN-ORIG

Below is the complete, readable transcript of Java Coding Questions Asked in Mastercard Interview by JAVA INTERVIEW BUDDY on YouTube. Read the full text, copy any part you need, or generate a transcript for any video with our free tool.
So our question is given a list of integers find the maximum value element present in it using stream function. So this question we need to solve using stream API and for that I have created a main method inside this class and I will create a list of numbers as well. So I will create I will quickly create a list
of integers. I will call this list numbers and I have certain values as well like 3 9 2 7 5 these are integers available inside this list. Now we need to find the maximum we need to find the maximum value using stream API. So it is a very simple question basically. So first I convert this list into a stream.
Okay. And then I use max function with a comparator. Yeah that's it. That's what we need to do. So I will use I will first convert that number list into a stream and then I will use a function called max and inside that I will use a comparator and comparator I I will
provide something like this. So basically comparator has this compare to method. So I will pass a and b and try to compare the values and get the maximum. Then finally I will use this get method to get that value. And uh here I will catch I mean I will collect this inside integer max and finally I
will print the value as well. Print the output as well. The output is in max. So I will print max. Just print it. Let's just check if it is working or not. So yeah it is working. It works because max this max function internally iterates over the stream and keeps tracks on the
largest element based on the comparator. So max return an optional max this if you check this max it returns an optional. Okay. So because the list could be empty as well. So that's why it it is returning optional. So that is why we are using that get this get method from the optional and it in real project
Transcribe another video
Paste any YouTube, Instagram or TikTok link to get a free transcript.