 Hi guys, welcome to our channel. So today I'm going to share one of the interview questions that I have recently encountered with DBS. So this was my third in the third round I'll go with some lead tech lead Techum manager wrong. So he in that round he asked me to create he actually given me an input of Stinger is let me quickly create one array So it was having some string values Again, there was one more So this was the input that was given by the click maybe he was ready with the input So he asked me to create a stream here. So how I have created the stream array So this was all happening while I was sharing my screen and he asked me to use Our idea I will get this list and he asked me to create a stream. So like this I have created the stream So I have named it Input So I got the stream. So now he asked me to print all the values inside that list. So it was very easy using for each Lambda it was simple. It was very easy I have to print the value Let me run he asked me to run. So I ran this application So everything came up like everything got printed. So now He asked me one question. So the stream which have created here Can I reuse it or not? Can I reuse that stream or not? So basically the question was that can we reuse a stream or not? So I was very much confident and I said, yes, why can't we use this? So he asked me to find like the count of each element Like he was he gave me an input on it like how many ammits are present in the string So it was very easy for me. So I went with Long count equal to stream. Filter of a predicate whatever the predicate Predicate here Ammits dot equals So I thought I'll be getting this count and he asked me to print that count I'm printing the count But it will work and I when I ran this look what will happen. So boom An exception and what is the exception stream has been operated upon or closed So we cannot use or reuse the same stream again and again So if at all I want to reuse it how the next question was that obviously it would there will be a question So at that moment, I was not aware of it So later on I learned it. So let me comment it out Commit it out this section and here comes the supplier Supplier which is in functional interface in Java 8 and That held that will help us. So let us create Supplier of Sorry string Which is in turn String So now this would be our input string That equals oh as fuck It is a function interface. It will have only one Method which is get of what happened stream Okay, I need to first input the supplier so stream of Directly I am passing the input array Now we will get the stream So far we know we got the same now if we see We can directly use these two lines the magic Coffee so So the same for okay input stream Okay, why it's not working. Oh, no, no, no, so we need to have the get method Dot for each year You're also the same thing goes Now see now we got it. So this is one of the use case waves Supplier interface comes to a rescue like if at all there is a scenario like I never face this scenario where I have to Reuse the same stream. So I couldn't answer this at that moment, but Using supplier interface we can reuse the same stream again and again. So this was one of the Learning from that interview Hope even if you are if you were not aware of this Then this might be a learning for you as well. If you were aware of it, can't do anything So that's it for this video. Thank you