Monday, April 10, 2017

String Interview Question

1    1.   how to find duplicate characters in a String.

22.    What is the similarity and difference between StringBuffer and StringBuilder class?
33       How do you count the number of occurrences of each character in a string?
4 4   Write a java program to check whether two strings are anagram or not?
55   Write a java program to reverse a given string with preserving the position of spaces?
66       How do you convert string to integer and integer to string in java?
77      Write a code to prove that strings are immutable in java?
88    Write a code to check whether one string is a rotation of another?
99     Write a java program to reverse each word of a given string?
110.    How many objects will be created in the following code and where they will be stored?
String s1 = new String("abc");

String s2 = new String("abc");

11. Can we call String class methods using string literals?

112.   What is the main difference between Java strings and C, C++ strings?
1
13.   How to program to print first non repeated character from String?
14.   How to reverse String in Java using Iteration and Recursion? 


15.   How to convert numeric String to an int?
16.   How to count number of vowels and consonants in a String?

How to find all permutations of String?
17.   I have seen this String interview question on many interviews. It has a easy recursive solution but thinks get really tricky when Interviewer ask you to solve this question without using recursion. You can use Stack though. Write a program to print all permutations of a String in Java, for example, the if input is "xyz" then it should print "xyz", "yzx", "zxy", "xzy", "yxz", "zyx".


18.   How to reverse words in a sentence without using library method? 

e.g. if an input is "Java is best programming language", the output should be "language programming best is Java"


 

19.How to check if String is Palindrome?



20. How to remove duplicate characters from String? (solution)

This is one of the interesting String question, which also has lots of variants. You need to remove duplicate characters from a given string keeping only the first occurrences. For example, if the input is ‘bananas’ the output will be ‘bans’. Pay attention to what output could be, because if you look closely original order of characters are retained the in output.

21. Write a program to find longest palindrome in a string? 
This is one of the tough coding question based upon String. It's hard to think about an algorithm to solve this problem until you have practiced good. What makes it more difficult is the constraint that your solution has O(n) time complexity and O(1) space complexity.


22. How to sort String on their length in Java?


23. Reverse a String Without using String API?
24. Sorting the String without using String API?
25. Removing Non Ascii character from a String?
·         1: Java Program to Remove non ASCII chars from String
·         #2: Java Program to Remove multiple spaces in a string
26.  5.How to split a String in java


·         #1: Java Program to split a String using String Split() method:
·         #2: Java Program to split a String using String Split() method and use for each loop to display  
·         #4: Java Program to split a String using String Split() method: Before splitting check whether deliminator is there or not
27. 7.Java program to replace or remove a character in a string java

·         #1: Java Program to Remove all occurrences of  char in a string  
·         #2: Java Program to Replace First occurance of Specific index char in a String
·         #3: Java Program to Remove all Numbers from a string.
28.java program to return maximum occurring character in the input string?
29. Java Program to find numbers of occurrences of given char in a string?
30. How to reverse vowels in a string java?
31. Java program to remove vowels from string?
32. How to find count of uppercase letters in a string ?

33. Why String is final in Java or why string objects are immutable?

34. Write a Java program to find the length of a String without using inbuilt functions.

35. Write a Java program to check  if given strings are Isomorphic.










No comments:

Post a Comment