Top 5 string programming interview questions in java

In almost all interview these programming questions are asking by interviewer.

 

1. Find Duplicate Characters from string


package practice.String; public class DuplicateCharacters { public static void main(String[] args) { String s = "Niraj Kumar Singh"; char[] chr = s.toCharArray(); int count; for (int i = 0; i < chr.length; i++) { count = 1; for (int j = i + 1; j < chr.length; j++) { if (chr[i] == chr[j] && chr[i] != ' ') { count++; chr[j] = '0'; } } if (count > 1 && chr[i] != '0') { // System.out.print(chr[i]); System.out.println(chr[i] + " is repeated :" + count); } } } }

 

2. Check String is Palindrome or not

We are Checking String is Palindrome or not Using String Buffer.


package practice.String; public class PalindromeString { public static void main(String Arg[]) { String s = "aba"; //Using StringBuffre reverse or Palindrome check StringBuffer sb = new StringBuffer(s); sb.reverse(); String reverse = sb.toString(); if (s.equals(reverse)) { System.out.println("String is Palindrome : " + s); } else { System.out.println("String is not Palindrome : " + s); } } }

 

Checking string is Palindrome without using StringBuffer or StringBuilder


package practice.String; public class PalindromeString { public static void main(String Arg[]) { String s = "aba"; //Without Using StringBuffer or StringBuilder reverse or Palindrome check String reverse=""; for(int i=s.length()-1; i>=0;i--) { reverse=reverse+s.charAt(i); } if (s.equals(reverse)) { System.out.println("String is Palindrome : " + s); } else { System.out.println("String is not Palindrome : " + s); } } }

 

3. Find duplicates words


package practice.String; public class FindDuplicatesWords { public static void main(String[] args) { int count; String s = "Raj Rahul Amit kumal Raj Munna"; s = s.toLowerCase(); String words[] = s.split(" "); for (int i = 0; i < words.length; i++) { count = 1; for (int j = i + 1; j < words.length; j++) { if (words[i].equals(words[j])) { count++; words[j] = "0"; } } if (count > 1 && words[i] != "0") { System.out.println(words[i]); } } } }

 

4. Remove duplicates from List of String


package practice.String; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; public class RemoveDuplicats { public static void main(String Arg[]) { List<String> ls = new ArrayList<String>(); ls.add("Rahul"); ls.add("Rahul"); ls.add("Amit"); ls.add("Niraj"); ls.add("kunal"); Set<String> st = new LinkedHashSet<String>(ls); System.out.println(ls); System.out.println(st); } }

 

5. Reverse String


package practice.String; public class ReverseString { public static void main(String Arg[]) { String s = "aba"; StringBuffer sb = new StringBuffer(s); sb.reverse(); String reverse = sb.toString(); if (s.equals(reverse)) { System.out.println("String is Reverse : " + s); } else { System.out.println("String is not Reverse : " + s); } } }

 

Hope this was helpful for you. If you have any questions please feel free to leave a comment. Thank you for reading.

17 Replies to “Top 5 string programming interview questions in java”

  1. Thanks for your own work on this website. My mum takes pleasure in setting aside time for research and it is simple to grasp why. We notice all relating to the powerful way you provide very important tips and hints via your website and therefore strongly encourage response from visitors on this theme while our own simple princess is without a doubt understanding so much. Take pleasure in the rest of the year. Your performing a useful job.

  2. I am glad for writing to make you know what a nice encounter our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the rest without problems understand various very confusing topics. You undoubtedly surpassed visitors’ expected results. Thanks for supplying those warm and helpful, trustworthy, revealing not to mention unique tips on your topic to Tanya.

  3. A lot of thanks for all your valuable efforts on this site. Kate loves engaging in investigation and it’s really easy to understand why. I know all concerning the dynamic medium you give important secrets on this web blog and as well as foster participation from others on that content plus our daughter is always discovering a lot. Have fun with the remaining portion of the new year. You are conducting a great job.

  4. Thank you for each of your hard work on this web page. My aunt takes pleasure in setting aside time for research and it is simple to grasp why. We notice all relating to the powerful ways you render very useful tips and tricks via your website and therefore strongly encourage response from website visitors on this theme while our own simple princess is without a doubt understanding so much. Take pleasure in the rest of the year. Your performing a very good job.

  5. I am only writing to make you understand what a really good experience my wife’s princess obtained viewing your webblog. She noticed some things, which included what it is like to possess an ideal teaching spirit to make others without difficulty learn about specific tortuous things. You undoubtedly surpassed readers’ expected results. Thanks for rendering those productive, trusted, informative as well as unique tips on your topic to Mary.

  6. Thanks for your entire labor on this web site. My mother take interest in participating in research and it is simple to grasp why. My spouse and i notice all regarding the powerful tactic you produce useful thoughts via your website and in addition recommend response from the others on this subject then our own princess is truly studying a whole lot. Take pleasure in the rest of the year. You have been performing a superb job.

  7. I’m just commenting to let you be aware of of the exceptional discovery my cousin’s child enjoyed going through your blog. She discovered a wide variety of details, most notably how it is like to have a very effective coaching heart to get many more effortlessly fully understand certain extremely tough matters. You actually did more than my desires. I appreciate you for displaying such helpful, healthy, educational and also cool guidance on that topic to Evelyn.

  8. My wife and i have been so peaceful when Michael managed to finish up his researching via the precious recommendations he obtained using your web site. It is now and again perplexing to simply happen to be making a gift of techniques which often some others might have been trying to sell. We recognize we need you to thank for this. The type of illustrations you made, the straightforward website navigation, the relationships your site make it easier to instill – it is most sensational, and it is letting our son in addition to us reckon that this subject matter is interesting, which is certainly tremendously serious. Thanks for the whole lot!

  9. I happen to be writing to make you understand what a wonderful experience our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the rest without problems understand various very confusing topics. You undoubtedly surpassed visitors’ expected results. Thanks for supplying those warm and helpful, trustworthy, revealing not to mention unique tips on your topic to Tanya.

  10. I’m also commenting to let you be aware of of the cool discovery my child encountered checking your blog. She came to understand a wide variety of details, most notably how it is like to have a marvelous coaching heart to get folks easily fully grasp a variety of complicated matters. You actually did more than my desires. I appreciate you for delivering such good, dependable, edifying and also cool guidance on that topic to Evelyn.

  11. I’m just commenting to let you be aware of of the extraordinary discovery my cousin’s daughter experienced going through your site. She even learned lots of issues, most notably how it is like to have a very effective giving mindset to have many others just gain knowledge of chosen extremely tough matters. You really did more than our desires. Many thanks for distributing the important, healthy, educational and as well as easy thoughts on the topic to Gloria.

  12. I am glad for writing to make you know what a magnificent encounter my friend’s girl gained studying your web site. She learned plenty of pieces, which include what it’s like to possess an awesome helping nature to let other folks very easily know just exactly several multifaceted subject matter. You truly exceeded people’s expectations. Thank you for presenting these powerful, safe, explanatory and in addition fun tips about this topic to Julie.

  13. My husband and i ended up being cheerful Albert could carry out his analysis because of the ideas he acquired from your blog. It’s not at all simplistic just to always be freely giving concepts a number of people could have been making money from. And now we acknowledge we’ve got the blog owner to appreciate because of that. All of the explanations you’ve made, the easy blog menu, the friendships you aid to create – it’s all amazing, and it’s aiding our son and our family believe that that article is amusing, and that’s especially essential. Many thanks for all!

  14. I precisely had to appreciate you all over again. I am not sure the things that I might have followed in the absence of the entire methods documented by you directly on such industry. It had become a real fearsome crisis in my circumstances, however , finding out the skilled form you managed that made me to jump over fulfillment. I’m just happier for this guidance and even hope you find out what a great job you are doing instructing other individuals through your blog post. I am sure you have never encountered all of us.

  15. I simply wished to thank you very much yet again. I do not know what I would have worked on without those ways shown by you relating to this topic. This was the troublesome situation in my view, nevertheless witnessing your well-written way you treated the issue took me to weep with joy. Now i am thankful for your work as well as wish you recognize what an amazing job your are undertaking training the rest with the aid of your websites. Probably you haven’t met any of us.

Leave a Reply

Your email address will not be published.