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

Sdílet
Vložit
  • čas přidán 7. 09. 2024

Komentáře • 116

  • @KanagalingamJothi
    @KanagalingamJothi Před 5 lety +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

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

  • @sabinchand4895
    @sabinchand4895 Před 2 lety +3

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

  • @sarath6789
    @sarath6789 Před 5 lety +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 Před 3 lety

      Contains shouldn't be used which leads to performance issue

    • @mokshanachannel9587
      @mokshanachannel9587 Před 3 lety

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

    • @user1994gms
      @user1994gms Před 3 lety

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

  • @meghavikshatriya5637
    @meghavikshatriya5637 Před 2 lety +1

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

  • @rakeshsaw
    @rakeshsaw Před rokem

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

  • @fafunmotavines
    @fafunmotavines Před 5 lety +1

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

  • @JoshMolina
    @JoshMolina Před 5 lety +5

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

    • @vicentedominic2753
      @vicentedominic2753 Před 3 lety

      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 Před 3 lety

      @Vicente Dominic Instablaster =)

    • @vicentedominic2753
      @vicentedominic2753 Před 3 lety

      @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 Před 3 lety

      @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 Před 3 lety

      @Vicente Dominic You are welcome =)

  • @tabishrizwan9137
    @tabishrizwan9137 Před 4 lety +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);
    }
    }

  • @MsDhruv001
    @MsDhruv001 Před 3 lety

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

  • @SpaceTimeBeing_
    @SpaceTimeBeing_ Před 4 lety

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

  • @Mylastpage
    @Mylastpage Před 5 lety +2

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

  • @hondahnesscb3505
    @hondahnesscb3505 Před 5 lety +4

    Starting music is same which Guru Maan Sir is using.

  • @hasanath9702
    @hasanath9702 Před 4 lety +1

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

  • @chidanandasutar9105
    @chidanandasutar9105 Před rokem

    Thanks for this video 🙏

  • @jimmyfallon1890
    @jimmyfallon1890 Před 5 lety +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 Před 5 lety

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

  • @thallasaikumar1778
    @thallasaikumar1778 Před 3 lety

    i love the way you explain the things

  • @prasannavadada6349
    @prasannavadada6349 Před 5 lety +1

    Awesome explanation brother keep rocking 🎸🎶🎶

  • @akshaybedre6804
    @akshaybedre6804 Před 3 lety +1

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

  • @nitinpatil1163
    @nitinpatil1163 Před 6 lety +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 ?

  • @sachingupta2859
    @sachingupta2859 Před 3 lety

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

  • @simm5622
    @simm5622 Před 2 lety

    Thank you. 🏆🏆🏆

  • @tejeswarv450
    @tejeswarv450 Před 5 lety

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

  • @kajalsarawgi3457
    @kajalsarawgi3457 Před 5 lety +3

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

  • @shakelahmed9722
    @shakelahmed9722 Před 4 lety

    Great explaining.Keep it up...

  • @suhedaerturk215
    @suhedaerturk215 Před 2 lety

    Great explanation!

  • @nishaant9
    @nishaant9 Před 5 lety

    good one

  • @ankitshah4211
    @ankitshah4211 Před 4 lety

    Nice explanation

  • @gamzeguresci5546
    @gamzeguresci5546 Před 4 lety +1

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

  • @sureshs2510
    @sureshs2510 Před 6 lety +2

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

  • @emilefeltesse
    @emilefeltesse Před 3 lety

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

  • @rajp3059
    @rajp3059 Před 5 lety

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

  • @sourav2726
    @sourav2726 Před 3 lety

    Just beautiful ❤️. make more videos man

  • @anjaliyadav8929
    @anjaliyadav8929 Před 3 lety

    Vdo👌

  • @fafunmotavines
    @fafunmotavines Před 5 lety

    Nicely explained....

  • @abhijeetdeshmukh9138
    @abhijeetdeshmukh9138 Před 5 lety

    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 Před 5 lety

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

  • @reddydivya8055
    @reddydivya8055 Před 6 lety

    Thanks sir! Great explanation

  • @karunakardatla2048
    @karunakardatla2048 Před 6 lety

    super explanation bro

  • @bhupendradhore8574
    @bhupendradhore8574 Před 4 lety

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

  • @ganeshsurya8115
    @ganeshsurya8115 Před 4 lety

    good boss

  • @krish.gottipati
    @krish.gottipati Před 3 lety

    Super bro,

  • @VC-kj9yx
    @VC-kj9yx Před 6 lety

    Very nice tutorial

  • @ansilbabariya9713
    @ansilbabariya9713 Před 3 lety

    You can use containskey method instead of get

  • @xcreatorminigames6227
    @xcreatorminigames6227 Před 6 lety

    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  Před 6 lety +1

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

  • @sanjaypaudel3296
    @sanjaypaudel3296 Před 2 lety

    Namaste guru

  • @abulhasanath1471
    @abulhasanath1471 Před 4 lety

    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 Před 4 lety +1

      if u want a video cantact me in whatsapp +917358252858

    • @hasanath9702
      @hasanath9702 Před 4 lety

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

  • @theLastOneTaken
    @theLastOneTaken Před rokem

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

  • @aniketchoubey2027
    @aniketchoubey2027 Před 5 lety

    Awwsome thnks

  • @AmeyaNanarkar76625
    @AmeyaNanarkar76625 Před 3 lety

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

  • @harishbs89
    @harishbs89 Před 4 lety

    Can use entrySet() which returns Entry Interface.

  • @playwithknight007
    @playwithknight007 Před 5 lety +1

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

    • @bhupendradhore8574
      @bhupendradhore8574 Před 4 lety +1

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

  • @aazaa7334
    @aazaa7334 Před 2 lety

    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);
    }
    }

  • @shobhitss
    @shobhitss Před 4 lety

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

  • @manish1315
    @manish1315 Před 5 lety +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  Před 5 lety +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 Před 5 lety

      @@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  Před 5 lety +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.

  • @singsarav
    @singsarav Před 5 lety

    Will it be easier if lambda was applied?

  • @sauravSingh037
    @sauravSingh037 Před 4 lety

    Thank you 😊😘❤️

  • @damodaranm3044
    @damodaranm3044 Před 4 lety

    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]);
    }


    }

    }

  • @umeshrgpv
    @umeshrgpv Před 6 lety

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

  • @ankitpriyadarshi2028
    @ankitpriyadarshi2028 Před 5 lety

    Make videos on jdbc and core java

  • @Mylastpage
    @Mylastpage Před 5 lety

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

  • @harshittiwari3947
    @harshittiwari3947 Před 6 lety

    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  Před 6 lety +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 Před 6 lety +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

  • @akkitech6259
    @akkitech6259 Před 5 lety

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

  • @IASGURUADVANCEPREPARATION

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

  • @manikanta783
    @manikanta783 Před 6 lety

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

    • @r.o.9322
      @r.o.9322 Před 4 lety

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

  • @kraljeliman2748
    @kraljeliman2748 Před 5 lety +1

    "right?"

  • @bulutcakan3048
    @bulutcakan3048 Před 5 lety

    why you did not use SET for find duplicate values.

    • @iam_ms9723
      @iam_ms9723 Před 5 lety

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

  • @kothiyan5655
    @kothiyan5655 Před 4 lety

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

  • @vinayakkanade1782
    @vinayakkanade1782 Před 2 lety

    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);
    }

  • @sachinsahu817
    @sachinsahu817 Před 5 lety

    {

    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 Před 5 lety

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

    • @JP-yf2kp
      @JP-yf2kp Před 5 lety +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 Před 5 lety

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

  • @SreeConnects
    @SreeConnects Před 4 lety

    nice but very lengthy code

  • @KanagalingamJothi
    @KanagalingamJothi Před 5 lety

    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 Před 5 lety +1

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

  • @rishirakh1
    @rishirakh1 Před 3 lety

    I thought I opened Guruman fitness video 😂

  • @randomize8053
    @randomize8053 Před 5 lety

    why we used iterator there , am not getting it ?

    • @Uda_dunga
      @Uda_dunga Před 5 lety

      to iterate ..its just like for loop

  • @princegamingff3744
    @princegamingff3744 Před 5 lety

    hi plz upload some video

  • @mrnagalakshmi93
    @mrnagalakshmi93 Před 4 lety +1

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

  • @abhay6276
    @abhay6276 Před 2 lety +1

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

  • @ViratKohali.television

    how to sovle xml parsing error in spring

  • @Raj-ql2vz
    @Raj-ql2vz Před 2 lety

    U copied background music from gurumann

  • @sivaprasad8333
    @sivaprasad8333 Před 3 lety

    No clarity