Java coding interview questions || Print duplicate occurrences of string in java

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

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

  • @KanagalingamJothi
    @KanagalingamJothi 5 ปีที่แล้ว +7

    String key = "I am am learning java java ";
    String[] words = key.split(" ");
    HashSet set = new HashSet();
    for (String s : words) {
    if (!set.add(s)) {
    Log.d("TAG", s);
    } else {
    set.add(s);
    }
    }

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

    I am an experienced java developer. Please upload more videos. It will be helpful for interviews. Thanks for this video

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

    I would say go with java 8 stream, it would be only one line of code!

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

    10:20 (Line 15) if(hm.get(tempString) != null)
    I think it checks 'value', not 'key'.

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

    You explain us in a very practical manner, easy to understand...

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

    I am impressed of your video and also I am first time commenting in any video.

  • @JoshMolina
    @JoshMolina 5 ปีที่แล้ว +5

    Great example! Thanks for sharing. Keep up the great work!

    • @vicentedominic2753
      @vicentedominic2753 3 ปีที่แล้ว

      i know Im randomly asking but does anyone know a trick to log back into an Instagram account..?
      I was stupid forgot the account password. I would appreciate any assistance you can offer me!

    • @rogerwilder8185
      @rogerwilder8185 3 ปีที่แล้ว

      @Vicente Dominic Instablaster =)

    • @vicentedominic2753
      @vicentedominic2753 3 ปีที่แล้ว

      @Roger Wilder I really appreciate your reply. I found the site thru google and Im in the hacking process atm.
      Seems to take quite some time so I will reply here later when my account password hopefully is recovered.

    • @vicentedominic2753
      @vicentedominic2753 3 ปีที่แล้ว

      @Roger Wilder it did the trick and I now got access to my account again. Im so happy!
      Thanks so much you saved my ass!

    • @rogerwilder8185
      @rogerwilder8185 3 ปีที่แล้ว

      @Vicente Dominic You are welcome =)

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

    Concise code
    String str ="I am am learning learning learning Java Java Java";
    String []st=str.split(" ");
    int count=0;
    Map stor = new HashMap();
    for(String s:st)
    {
    if(stor.containsKey(s))
    {
    count++;
    stor.put(s,count);
    }
    else
    {
    count=1;
    stor.put(s,count);
    }
    }

    • @user1994gms
      @user1994gms 3 ปีที่แล้ว

      Contains shouldn't be used which leads to performance issue

    • @mokshanachannel9587
      @mokshanachannel9587 3 ปีที่แล้ว

      What if string has"i am learning Java and Java"

    • @user1994gms
      @user1994gms 3 ปีที่แล้ว

      @@mokshanachannel9587 above program is wrong..
      If repeated words are not contiguous count will be wrong..
      Consider 'am' word is in sentence.
      Count is 1..
      Next word is different.. count is 1
      Again 'am' in a sentence.. count++ becomes 2
      Next word is different.. count is 1
      Again 'am' here count should be 2+1, but the above program returns 1+1 which is incorrect

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

    Thanks for this video 🙏

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

    Starting music is same which Guru Maan Sir is using.

  • @thallasaikumar1778
    @thallasaikumar1778 3 ปีที่แล้ว

    i love the way you explain the things

  • @anjaliyadav8929
    @anjaliyadav8929 3 ปีที่แล้ว

    Vdo👌

  • @MsDhruv001
    @MsDhruv001 3 ปีที่แล้ว

    Somewhere i have feeling that you made problem more complex while solving

  • @nishaant9
    @nishaant9 5 ปีที่แล้ว

    good one

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

    Video ke starting me jo Audio hai. Kya nam hai uska???

  • @ankitshah4211
    @ankitshah4211 4 ปีที่แล้ว

    Nice explanation

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

    you can use in this way also it's simple like your previous program bro
    public class duplicatechar {
    private static void findDuplicateChar(String string) {
    char[] ch = string.toCharArray();
    HashMap hm = new HashMap();
    for (char c : ch) {
    if (hm.get(c) != null) {
    hm.put(c, hm.get(c) + 1);
    } else {
    hm.put(c, 1);
    }
    }

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

    Awesome explanation brother keep rocking 🎸🎶🎶

  • @simm5622
    @simm5622 2 ปีที่แล้ว

    Thank you. 🏆🏆🏆

  • @sachingupta2859
    @sachingupta2859 3 ปีที่แล้ว

    Please try- Find occurrences of given substring in given string with optimized code.

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

    Great explanation!

  • @ganeshsurya8115
    @ganeshsurya8115 4 ปีที่แล้ว

    good boss

  • @sanjaypaudel3296
    @sanjaypaudel3296 2 ปีที่แล้ว

    Namaste guru

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

    static void findDuplicate(String text) {
    String[] strAr = text.split(" ");
    Set set = new HashSet();
    Map map = new HashMap();
    for(int i=0;i

  • @shakelahmed9722
    @shakelahmed9722 4 ปีที่แล้ว

    Great explaining.Keep it up...

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

    How to remove duplicate in a string (using java) can you please make a video for that ...Thanks

  • @krish.gottipati
    @krish.gottipati 3 ปีที่แล้ว

    Super bro,

  • @tejeswarv450
    @tejeswarv450 5 ปีที่แล้ว

    Awesome explanation sir .... representation is suuuuuper....

  • @SpaceTimeBeing_
    @SpaceTimeBeing_ 4 ปีที่แล้ว

    This is all you need.
    var map = new HashMap();
    for(String word : stringArray){
    map.merge(word.toLowerCase().replaceAll("[^a-zA-Z]", ""), 1, Integer::sum);
    }
    System.out.println(map);

  • @kajalsarawgi3457
    @kajalsarawgi3457 5 ปีที่แล้ว +3

    thanks brother, you are teaching exactly the way i want. :)

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

    good explanation , whats happens in case of Variable? if there is same variable in both parent and child class then which one gets called ?

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

    Really worth videos thanks a lot .. could you please prepare one video of java 8 features please

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

      Thanks, Suresh. Sure will prepare one soon.

    • @sureshs2510
      @sureshs2510 6 ปีที่แล้ว

      Thanks for replying

  • @rajp3059
    @rajp3059 5 ปีที่แล้ว

    Superb bro...keep rocking for ur explanation bro...

  • @fafunmotavines
    @fafunmotavines 5 ปีที่แล้ว

    Nicely explained....

  • @sourav2726
    @sourav2726 3 ปีที่แล้ว

    Just beautiful ❤️. make more videos man

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

    I paused the video and did a dirty log(n)2 version....
    String str = "I am am learning java java ";
    String[] result = str.split(" ");
    ArrayList list = new ArrayList();
    for(int i = 0; i

    • @SauravKumar-cs4oj
      @SauravKumar-cs4oj 5 ปีที่แล้ว

      Good code but what in case we also want the count of the repeated words?

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

    Hi thank you for the video. Can you also write the unit test for this example ?

  • @VC-kj9yx
    @VC-kj9yx 6 ปีที่แล้ว

    Very nice tutorial

  • @reddydivya8055
    @reddydivya8055 5 ปีที่แล้ว

    Thanks sir! Great explanation

  • @karunakardatla2048
    @karunakardatla2048 6 ปีที่แล้ว

    super explanation bro

  • @aniketchoubey2027
    @aniketchoubey2027 5 ปีที่แล้ว

    Awwsome thnks

  • @emilefeltesse
    @emilefeltesse 3 ปีที่แล้ว

    Cool. But what if we want out the words in the same order as they appear in the initial sentence?

  • @ansilbabariya9713
    @ansilbabariya9713 3 ปีที่แล้ว

    You can use containskey method instead of get

  • @bhupendradhore8574
    @bhupendradhore8574 4 ปีที่แล้ว

    Why you have used iterator you can use for each loop for iterating through values

  • @harishbs89
    @harishbs89 4 ปีที่แล้ว

    Can use entrySet() which returns Entry Interface.

  • @sauravSingh037
    @sauravSingh037 4 ปีที่แล้ว

    Thank you 😊😘❤️

  • @xcreatorminigames6227
    @xcreatorminigames6227 6 ปีที่แล้ว

    Very nice friend, but you can use the computer to work as a blackbord, so we can see your writings better, and the sound is better too :-)

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

      Thank you, Vinicius.. I will keep your suggestions in mind. Thank you for taking time and writing a feedback.
      Have a nice time 😊

  • @abhijeetdeshmukh9138
    @abhijeetdeshmukh9138 5 ปีที่แล้ว

    What if string contains punctuation marks like
    "I am working on java. Because java is my favourite language."
    In this case java is not showing as duplicate word. Because there is full stop. Please explain one example with punctuation mark.

    • @fafunmotavines
      @fafunmotavines 5 ปีที่แล้ว

      First split based on punctuation using regex and one more for loop...that will work

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

    Instead of hashmap u should've used set cuz it doesn't store duplicate values...

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

    bhai itni coding to kabhi yaad nahi hogi kya golmaal hai
    hasmap to java mein mene abhi padha bhi nahi hai
    dara diya apne mujhe

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

      Hi Manish,
      I appreciate ki apne at list video dekha, hashmap ka concept Na jante huea v.. Mein jab Ye Sab sikhta tha, I also had the same feelings and even I was not trying to watch these kind of programs. 😀so you are already doing better than me 👍
      So avi Apko pehele hashmap ka concepts sikhna hai.. Then you need to play with these logic's.
      And before you try solving any kind of logic, make sure you know ki app Kya karne Ja rahe ho.. Then Ye Bahot asan lagega..
      I know you can do it once you understand the concept 😊👍

    • @manish1315
      @manish1315 5 ปีที่แล้ว

      @@SeleniumExpress sir ek last question meine bsc cs last year complete kar loonga lekin abhi tak hamein is baare mein bataya kyun nahi
      sir mene java ka course bhi kiya tha lekin unhone bhi is baare mein nahi bataya
      kya ye advanced level ka to nahi hai vaise mein java ke advanced level like jsp servlet , netbeans ide project , like stand alone applicaiton , mysql sever , etc ke baare mein janta hoon
      kya kisi company mein interview ke liye java ke core concept hi puchhe jaate hai koi netbeans ke graphical question nahi puchta kya
      please help

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

      Manish,ye sare logical programs interviews mein Bahot importance rakhte hain.. Most of the time the first round is problem solving round where you will get questions like this..
      So ap collection framework pe jyada homework kijiye.. Because most of the questions you will get from there.

  • @AmeyaNanarkar76625
    @AmeyaNanarkar76625 3 ปีที่แล้ว

    Why not used hm.contains(tempString) in if condition at line 15

  • @ankitpriyadarshi2028
    @ankitpriyadarshi2028 5 ปีที่แล้ว

    Make videos on jdbc and core java

  • @abulhasanath1471
    @abulhasanath1471 4 ปีที่แล้ว

    print duplicate characters in a string (using java) can you please make a video for that also how to remove duplicate string or char ..thank you

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

      if u want a video cantact me in whatsapp +917358252858

    • @hasanath9702
      @hasanath9702 4 ปีที่แล้ว

      @@damodaranm3044 How to remove duplicate in a string (using java) can you please make a video for that ...Thanks using same code

  • @singsarav
    @singsarav 4 ปีที่แล้ว

    Will it be easier if lambda was applied?

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

    what about spaces, if we have spaces how to remove that spaces while counting

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

      You can use replace function to replace space with no-space Replace(" ","") like this

  • @umeshrgpv
    @umeshrgpv 6 ปีที่แล้ว

    Do you know how to create videos using our own laptop.. which software can be used without any charges?

  • @SreeConnects
    @SreeConnects 4 ปีที่แล้ว

    nice but very lengthy code

  • @shobhitss
    @shobhitss 4 ปีที่แล้ว

    If I want the input through excel and display the duplicates. How to do?

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

    "right?"

  • @IASGURUADVANCEPREPARATION
    @IASGURUADVANCEPREPARATION 5 ปีที่แล้ว

    Bro can know to make the table format (match type questionsin strings

  • @Mylastpage
    @Mylastpage 5 ปีที่แล้ว

    concurrentHaspMap would not be better? where you are iterating, you can remove all the elements having value 1.

  • @manikanta783
    @manikanta783 6 ปีที่แล้ว

    Frd super videos, but I want how to remove duplicates in string

    • @r.o.9322
      @r.o.9322 4 ปีที่แล้ว

      ArrayList d = new ArrayList();
      String sentence = "I am am learning Java Java";
      String[] s = sentence.split(" ");
      for (String a : s) {
      if(!d.contains(a))
      {
      d.add(a);
      }
      }
      System.out.println(d);

  • @damodaranm3044
    @damodaranm3044 4 ปีที่แล้ว

    i wonder why do u use hashmap
    any datastucture can do this
    String str = "i am am learning java java";

    String[] arr = str.split(" ");

    ArrayList al = new ArrayList();

    for(int i = 0 ; i < arr.length ; i++ ) {

    if(!al.contains(arr[i])) {
    al.add(arr[i]);
    }
    else {
    System.out.println(arr[i]);
    }


    }

    }

  • @vinayakkanade1782
    @vinayakkanade1782 2 ปีที่แล้ว

    public static void countDuplicateWord(String string){
    String sourceArr[] = string.split(" ");
    Map stringIntegerMapMap = new HashMap();
    for (String str : sourceArr) {
    Integer previousValue = stringIntegerMapMap.put(str, 1);
    if (previousValue != null) {
    stringIntegerMapMap.put(str, previousValue + 1);
    }
    }
    System.out.println(stringIntegerMapMap);
    }
    public static void countDuplicateCharacter(String word){
    Map characterIntegerMap = new HashMap();
    for (int i = 0; i < word.length(); i++) {
    Integer previousValue = characterIntegerMap.put(word.charAt(i), 1);
    if (previousValue != null) {
    characterIntegerMap.put(word.charAt(i), previousValue + 1);
    }
    }
    System.out.println(characterIntegerMap);
    }

  • @akkitech6259
    @akkitech6259 5 ปีที่แล้ว

    String s="this is java program"
    I want to find the index of 'is' in string. But when I find using indexOf("is") it return the index of first is which is in 'this' word. Can u tell me how to find that....

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

      In your case, you can use lastIndexOf("is")

    • @basernishant
      @basernishant 3 ปีที่แล้ว

      use " is" give some gap i think

  • @bulutcakan3048
    @bulutcakan3048 5 ปีที่แล้ว

    why you did not use SET for find duplicate values.

    • @iam_ms9723
      @iam_ms9723 5 ปีที่แล้ว

      Because we needed key and values pair so here he's using map

  • @harshittiwari3947
    @harshittiwari3947 6 ปีที่แล้ว

    Bro make a method in java that iterate prime number between 0-200 and return the prime number between 0-20 and 70-90

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

      Hi Harshit.Hope below code will help.Revert back for any further query.
      static void check()
      {
      ArrayList list = new ArrayList();
      for(int i = 0 ; i= 0 && tempInt = 70 && tempInt

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

      or u can simply write like this..
      for (Iterator iterator = a.iterator(); iterator.hasNext();)
      {
      Integer obj = (Integer) iterator.next();

      if (obj>=2 && obj=70 && obj

  • @rishirakh1
    @rishirakh1 3 ปีที่แล้ว

    I thought I opened Guruman fitness video 😂

  • @kothiyan5655
    @kothiyan5655 4 ปีที่แล้ว

    Can anyone explain hm.put(tempting,him.get(tempstring)+1)

  • @princegamingff3744
    @princegamingff3744 5 ปีที่แล้ว

    hi plz upload some video

  • @sachinsahu817
    @sachinsahu817 5 ปีที่แล้ว

    {

    map.put(str1, map.get(str1) + 1);
    }
    this line is not working.
    error message - The operator + is undefined for the argument type(s) Object, int
    can you please what I can do here?
    Thanks in Advance.

    • @krishnasingh9111
      @krishnasingh9111 5 ปีที่แล้ว

      I am getting same error if resolve please post your solution ..

    • @JP-yf2kp
      @JP-yf2kp 5 ปีที่แล้ว +1

      you cannot get such a error:-
      check this program
      package myapp;
      import java.util.HashMap;
      import java.util.Map;
      public class DuplicateString {
      public static void main(String[] args) {
      String str = "I am am learning java java";
      DuplicateString obj = new DuplicateString();
      obj.calculateDuplicateString(str);
      }

      public void calculateDuplicateString(String str) {
      Map string_literals_map = new HashMap();
      String [] str_array = str.split(" ");
      for (String str_literals : str_array) {
      //System.out.println(str_literals);
      if(string_literals_map.containsKey(str_literals)) {
      string_literals_map.put(str_literals, string_literals_map.get(str_literals) + 1);
      }
      else {
      string_literals_map.put(str_literals, 1);
      }
      }

      System.out.println(string_literals_map);
      }
      }

    • @JP-yf2kp
      @JP-yf2kp 5 ปีที่แล้ว

      @@krishnasingh9111
      package myapp;
      import java.util.HashMap;
      import java.util.Map;
      public class DuplicateString {
      public static void main(String[] args) {
      String str = "I am am learning java java";
      DuplicateString obj = new DuplicateString();
      obj.calculateDuplicateString(str);
      }

      public void calculateDuplicateString(String str) {
      Map string_literals_map = new HashMap();
      String [] str_array = str.split(" ");
      for (String str_literals : str_array) {
      //System.out.println(str_literals);
      if(string_literals_map.containsKey(str_literals)) {
      string_literals_map.put(str_literals, string_literals_map.get(str_literals) + 1);
      }
      else {
      string_literals_map.put(str_literals, 1);
      }
      }

      System.out.println(string_literals_map);
      }
      }

  • @randomize8053
    @randomize8053 5 ปีที่แล้ว

    why we used iterator there , am not getting it ?

    • @Uda_dunga
      @Uda_dunga 5 ปีที่แล้ว

      to iterate ..its just like for loop

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

    Annoying slang... sorry... unable to graspe the content coz of this slang.... looks artificial....

  • @KanagalingamJothi
    @KanagalingamJothi 5 ปีที่แล้ว

    String key = "I am am learning java java ";
    String[] words = key.split(" ");
    for (int i = 0; i < words.length; i++) {
    for (int j = i + 1; j < words.length; j++) {
    if (words[i].equalsIgnoreCase(words[j])) {
    Log.d("TAG", words[i]);
    }
    }
    }

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

      But in this case time complexity is O(n^2).

  • @Raj-ql2vz
    @Raj-ql2vz 2 ปีที่แล้ว

    U copied background music from gurumann

  • @ViratKohali.television
    @ViratKohali.television 6 ปีที่แล้ว

    how to sovle xml parsing error in spring

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

    You are creating complex coding...when beginners will watch your coding then he will suicide...

  • @sivaprasad8333
    @sivaprasad8333 3 ปีที่แล้ว

    No clarity

  • @aazaa7334
    @aazaa7334 2 ปีที่แล้ว

    String str1 = "I am am walking walking java java java java";
    String[] strings = str1.split(" ");
    Map myMap = new HashMap();
    for(String x : strings){
    if(!myMap.containsKey(x)){
    myMap.put(x,1);
    } else{
    myMap.put(x,myMap.get(x) + 1);
    }
    }
    Set keys = myMap.keySet();
    for(String key: keys){
    if(myMap.get(key)> 1){
    System.out.println(key);
    }
    }