Program on String in JAVA
Program on String in JAVA
8. Write a JAVA program to find total number of alphabets, digits or special character in a string.
9. Write a JAVA program to count total number of vowels and consonants in a string.
25.Write a JAVA program to remove all repeated characters from a given string.
26.Write a JAVA program to replace first occurrence of a character with another in a string.
27.Write a JAVA program to replace last occurrence of a character with another in a string.
28.Write a JAVA program to replace all occurrences of a character with another in a string.
36.Write a JAVA program to trim leading white space characters from given string.
37.Write a JAVA program to trim trailing white space characters from given string.
38.Write a JAVA program to trim both leading and trailing white space characters from given string.
39.Write a JAVA program to remove all extra blank spaces from given string.
40. WAP a JAVA program to reverse the string without using inbuilt functions ?
41. WAP a JAVA Program to check strings are anagram to each other or not ?
anagram string means string contain the equal character but sequence not match
42. WAP a JAVA program to print first non-repeated character from String?
Description: I have seen this String interview question on many interviews. It has an easy recursive
solution but things get really tricky when Interviewer asks you to solve this question without using
recursion. You can use a 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".
46. How to reverse words in a sentence without using a library method?
Write a function, which takes a String word and returns sentence on which words are reversed in
order like if the input is "Java is best programming language", the output should be "language
programming best is Java".
Another easy coding question based upon String, I am sure you must have done this numerous time.
Your program should return true if String is a Palindrome, otherwise false. For example, if the input
is "radar", the output should be true, if the input is "madam" output will be true, and if the input
is "Java" output should be false.
One more difficult String algorithm based coding question for senior developers. You are given 3
strings: first, second, and third. Third String is said to be a shuffle of first and second if it can be
formed by interleaving the characters of first and second String in a way that maintains the left to
right ordering of the characters from each string.
For example, given first = "abc" and second = "def", third = "dabecf" is a valid shuffle since it
preserves the character ordering of the two strings. So, given these 3 strings write a function that
detects whether the third String is a valid shuffle of first and second String.
You need to write a function to implement an algorithm which will accept a string of characters and
should find the highest occurrence of the character and display it. For example if input is
"aaaaaaaaaaaaaaaaabbbbcddddeeeeee" it should return "a".
his 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 well. What makes it more difficult is the constraint that
your solution has O(n) time complexity and O(1) space complexity.
Write a Program to sort String on their length in Java? Your method should accept an array of String
and return a sorted array based upon the length of String. Don't forget to write unit tests for your
solution.
That's all on this list of 15 String Algorithm based coding questions. These are a really good question
to prepare for programming job interviews, not only you can expect the same question on a real
interview but also it will prepare you how to tackle algorithmic coding interview questions. Even if
you don't find the same question, you would be able to apply the knowledge you gain by solving
these question by yourself.
Always remember, you are judged by the code you write, so always write production quality code,
which would pass the general test, corner cases, invalid inputs, robustness test and also pass the
performance test. Whenever asked to solve a coding problem, always think about all possible input
and write a test for that.