String Manipulation in Java - Interview questions - Part -7

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2024
  • String Manipulation - Different Methods in Java. String Interview Questions.
    --About java.lang.String, why String is special in java - String tutorial
    Learn Different Methods in String Class:
    1. length()
    2. charAt()
    3. indexOf()
    4. SubString()
    5. equal/equalsIgnoreCase() - String Comparison
    6. trim()
    7. replace()
    8. split()
    9. concat()
    10. String Concatenation using + operator
    ======================================================
    Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion:
    t.me/joinchat/COJqZQ4enmEt4JA...
    ~-~~-~~~-~~-~
    Follow my Site/Blog: www.naveenautomationlabs.com
    ========================================================
    Please watch: "Selenium & Automation Interview Preparation - By Naveen AutomationLabs"
    • Selenium & Automation ...
    ~-~~-~~~-~~-~ Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    th-cam.com/users/Naveen%20Au...
    Follow me on my Facebook Page:
    / naveenqtpexpert
    Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
    t.me/joinchat/COJqZUPB02r5sB7...
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p... ➡️Get Our Courses✔️
    📗 Get My Paid Courses at
    Paid courses (Recorded) videos:
    Java & Selenium Course: www.naveenautomationlabs.com/p...
    API Course: www.naveenautomationlabs.com/p...
    -------------------------------
    ✔️SOCIAL NETWORKS
    Facebook: / naveenqtpexpert
    Twitter: / naveenkhunteta
    Blog: www.naveenautomationlabs.com
    --------------------------------
    Support My Channel✔️Or Buy Me A Coffee
    Paypal: paypal.me/naveenkhunteta
    Google Pay: naveenanimation20@gmail.com
    --------------------------------
    ✔️Thanks for watching!
    देखने के लिए धन्यवाद
    Благодаря за гледането
    感谢您观看
    Merci d'avoir regardé
    Grazie per la visione
    Gracias por ver
    شكرا للمشاهدة
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @rajatgoyal7155
    @rajatgoyal7155 6 ปีที่แล้ว +7

    I have purchased 2 courses to understand Selenium and Java and i spent almost 13k rupees, they didn't tell me so elaborately even after charging so much. your tutorials are really helpful, one can easily understand and learn, moreover they can get enough confidence in few days to crack any MNC interview. Great job Naveen. Keep it up. please keep these tutorials free in future as well.

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

    Sir, no words for your explanation. You are simply born to teach!!!!

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

    occurrence of third 's'
    System.out.println(str.indexOf('s', str.indexOf('s', str.indexOf('s')+1)+1));

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

    Thank you so much Naveen for this video, really got clear picture on String methods.

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

    very helpful, I used to watch your video, The way you explaining the things is very easy to understand.

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

    Thanks for your efforts Naveen Sir, it is really worthful for me to clear concept in java

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

    This helps me a lot , thank you so much , this makes my java basic is so clear , and recently have interview , your interview section also helps me a lot .

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

    very good and very helpful. Thanks a lot Naveen!

  • @aparnabhosale7483
    @aparnabhosale7483 4 หลายเดือนก่อน

    so beautifuuly explained..thnku sir

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

    Awesome lecture...

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

    Really awesome tutorial!

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

    Thank you so much, this helps alot.

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

    Sir I got a doubt as string is immutable how can we concatenate and assign to same string, just read on net that a new string is created and it reference is set to the object reference.

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

    Nice video..

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

    Thanks a lot !
    Please do a few programs on Collections...

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

    one doubt Output2.IndexOf("W",Output2.IndexOf("W")+1) how will i get the index of 3rd occruence of W in string

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

    Hi Naveen. Nice video. Could you please prepare a video for Regex ?

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

    Awesome

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

    Thanks a lot

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

    Telegram link is expired... Is there new link?

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

    Thank u

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

    sir where is == i.e s1==s2

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

    The letters are not clearly visible. Explanation is good.

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

    Hi Naveen can you add program to find (first and last)non repeated character in a string

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

      package javaPrograms;
      public class NonRepeatingChar {
      public static void main(String[] args) {
      String str = "INDIAFORINDIANSFIRST";
      System.out.println("FIRST NON REPEATING CHARACTER IS : " + findFirstNonRepeatingCharacter(str));
      System.out.println("LAST NON REPEATING CHARACTER IS : " + findLastNonRepeatingCharacter
      (str));
      }
      public static char findFirstNonRepeatingCharacter(String str) {
      str = str.toUpperCase();
      char chr = 0;
      for (int i = 0; i < str.length(); i++) {
      if (!str.substring(i + 1).contains(Character.toString((str.charAt(i))))) {
      chr = str.charAt(i);
      break;
      }
      }
      return chr;
      }
      public static char findLastNonRepeatingCharacter(String str) {
      str = str.toUpperCase();
      char chr = 0;
      for (int i = 0; i < str.length(); i++) {
      if (!str.substring(0, str.length() - i - 1)
      .contains(Character.toString((str.charAt(str.length() - i - 1))))) {
      chr = str.charAt(str.length() - i - 1);
      break;
      }
      }
      return chr;
      }
      }

  • @shilpathada5832
    @shilpathada5832 3 ปีที่แล้ว +7

    String str = "The rains have started here selenium";
    System.out.println(str.indexOf(('s'), str.indexOf('s') + str.indexOf('s')+1));//3rd occurrence of 's'

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

      This one works as well:
      System.out.println(str.indexOf('s',str.indexOf('s')+str.indexOf('s',+1)));

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

      System.out.println(str.indexOf('s',str.indexOf('s' +1)+1)); its this correct way to find 3rd veriable?

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

    sir, please help me i really confuse between them what is the difference between the "array.length and array.length()" some time array.length will work and some time array.length() will work. is there is any rules for is for using it? with String arr.length() will work but when we use an integer type, its work with array.length.

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

      As far as I know you can not use .length( )with array. For find the length of an array you should write array.length. Like if String s = "test", the you can write s.length(). and if you have int numbers[] = {-10,-10,24,50,-88,276435}; the you can write int len = numbers.length;

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

      length is use to find the size of the array and length() is use to find the size of the string.

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

      @@kapilrana2361 you are right array.length is a variable and array.length() is a method.

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

    Hey Naveen anna you are doing great job I'm finding these days that everyone suggesting ur videos to others in selenium groups and everywhere though ur channel is quite is new u r reaching aspirants very quickly ....and help me with this
    I'm not able to print 3rd occurance of 's'...I did this System.out.println(s.indexOf('s', s.indexOf('s', s.indexOf('s')+1))); ...

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

      starting index should be 15;
      String str = "The rains have started here in selenium";
      System.out.println(str.length());
      System.out.println(str.charAt(5));
      System.out.println(str.indexOf("s"));
      System.out.println(str.indexOf("s", str.indexOf("s")+1));
      System.out.println(str.indexOf("s", str.indexOf("s")+15));

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

      If any one done this plz post here

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

      public static void main(String[] args) {
      FindNthIndexOfACharacter('s', "The rains have started here in selenium", 3);
      }
      private static void FindNthIndexOfACharacter(char c, String str, int position) {
      int count = 0;
      //str = str.replaceAll("\\s", ""); -- uncomment this line if you want to remove spaces
      for (int i = 0; i < str.length(); i++) {
      if (str.toUpperCase().charAt(i) == Character.toUpperCase(c)) {
      count += 1;
      if (count == position) {
      System.out.println(i);
      break;
      }
      }
      }

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

      @@saranyasanapala1049 String str ="The rain has started here for some reason";
      System.out.println("The location of second occurence of 's' is :" +str.indexOf('s',str.indexOf('s')+1));
      System.out.println("The location of third occurence of 's' is :" +str.lastIndexOf('s', str.lastIndexOf('s')-1));
      System.out.println("The location of last occurence of 's' is :" +str.lastIndexOf('s'));

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

      System.out.println(str.indexOf('s', str.indexOf('s',str.indexOf('s')+1)));

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

    Hi Naveen, i am unable to print the 3rd occurance in the sentence, tried it in many ways. Google is having some complex code.
    Could you please provide your inputs.

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

      Thanks

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

      I think we can use OrdinalIndexOf in StringUtils

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

      str.indexOf(‘s’, str.indexOf(‘s’, str.indexOf(‘s’, str.indexOf(‘s’)+1)+1)

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

    PLEASE MAKE VIDEOS ON ZOOM MODE. I AM NOT ABLE TO SEE YOUR CODES PROPERLY...

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

    Lets take this example
    String s="_Hello_world_";
    String test[]=s.split("_");
    System.out.println(test.leangth);// Return 3: Why?

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

    System.out.println(str.indexOf('s',str.indexOf('s' +1)+1)); //3rd occurrence of s or any occurrence

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

      is it correct? im getting the correct answer but im not sure whether we can do this way

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

      @buvanan Rajendiran - Is this correct way to get third occurence of s?

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

    can somebody write here, how to find the third occurrence of 's' in string. thanks in advance. :)

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

      System.out.println(str.indexOf(('s'), str.indexOf('s') + str.indexOf('s')+1));

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

    String str="ae@io#b$u123";
    Separate characters,special characters and numbers......this was a interview question. sir,plz answer this

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

      public class StringManipulation {
      public static void main(String[] args) {
      String str2 = "ae@io#b$u123";
      System.out.println("Characters are : "+ str2.replaceAll("[^a-zA-Z]", ""));

      System.out.println("Numbers are : "+ str2.replaceAll("[^0-9]", ""));
      System.out.println("Special characters are : "+ str2.replaceAll("[a-zA-Z0-9]", ""));
      }
      }
      O/P
      Characters are : aeiobu
      Numbers are : 123
      Characters are : @#$

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

      String s1 = "ae@io#b$u123";
      ArrayList alString = new ArrayList();
      alString.add(s1.replaceAll("[^a-z]", ""));
      alString.add(s1.replaceAll("[a-z0-9]", ""));
      alString.add(s1.replaceAll("[^0-9]", ""));
      System.out.println(alString);

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

    Hi Naveen!
    How to find the numbers of ‘L’ in a string “GOOGLLLLLEE”?

    • @_abhimanyu.
      @_abhimanyu. 5 ปีที่แล้ว

      we can do this using HashMap

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

      public int lengthOf()
      {
      String s="GOOGLLLLLEE";
      int first=s.indexOf('L');
      int last=s.lastIndexOf('L');
      int counter=0;
      for(int i=first;i

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

      String s = "GOOGLLLLLEE";
      int counter =0;
      for(int i=0; i

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

      package javaPrograms;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Map.Entry;
      public class CountChar {
      public static void main(String[] args) {
      String inputStr = "GOOGLLLLLEE";

      Map myMap = countCharacters(inputStr);
      for (Entry entry : myMap.entrySet()) {
      System.out.println(entry.getKey() + " : " + entry.getValue());
      }
      }
      public static Map countCharacters(String str) {
      Map map = new HashMap();
      int counter = 1;
      for (int i = 0; i < str.length(); i++) {
      if (!map.containsKey(str.charAt(i))) {
      map.put(str.charAt(i), counter);
      }
      else {
      map.put(str.charAt(i), map.get(str.charAt(i)) + 1);
      }
      }
      return map;
      }
      }

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

      String a="GOOGLLLLLEE";
      int b=(int)a.chars().filter(e->e=='L').count();
      System.out.print(b);

  • @ParthKandpal
    @ParthKandpal 4 ปีที่แล้ว +3

    Hi Naveen,
    Please find below the code for 3rd occurence of s
    String str="The Rains have started here selenium";
    System.out.println(str.indexOf("s", str.indexOf("s")+str.indexOf("s")+1));
    output will be -->28
    Thanks :)

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

      System.out.println(str.indexOf('s',str.indexOf('s' +1)+1)); its this correct way to find 3rd veriable?