0% found this document useful (0 votes)
9 views4 pages

Program on String in JAVA

The document provides a comprehensive list of 51 Java programming tasks focused on string manipulation, including finding string length, copying, concatenating, comparing, and various transformations. It also includes advanced tasks such as checking for palindromes, finding the longest palindrome, and validating shuffles of strings. This collection serves as a valuable resource for preparing for programming job interviews, emphasizing the importance of writing production-quality code.

Uploaded by

komalpise22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
9 views4 pages

Program on String in JAVA

The document provides a comprehensive list of 51 Java programming tasks focused on string manipulation, including finding string length, copying, concatenating, comparing, and various transformations. It also includes advanced tasks such as checking for palindromes, finding the longest palindrome, and validating shuffles of strings. This collection serves as a valuable resource for preparing for programming job interviews, emphasizing the importance of writing production-quality code.

Uploaded by

komalpise22
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

1. Write a JAVA program to find length of a string.

2. Write a JAVA program to copy one string to another string.

3. Write a JAVA program to concatenate two strings.

4. Write a JAVA program to compare two strings

5. Write a JAVA program to convert lowercase string to uppercase.

6. Write a JAVA program to convert uppercase string to lowercase.

7. Write a JAVA program to toggle case of each character of a string.

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.

10.Write a JAVA program to count total number of words in a string.

11.Write a JAVA program to find reverse of a string.

12. Write a JAVA program to check whether a string is palindrome or not.

13.Write a JAVA program to reverse order of words in a given string.

14.Write a JAVA program to find first occurrence of a character in a given string.

15.Write a JAVA program to find last occurrence of a character in a given string.

16.Write a JAVA program to search all occurrences of a character in given string.

17.Write a JAVA program to count occurrences of a character in given string.

18.Write a JAVA program to find highest frequency character in a string.

19.Write a JAVA program to find lowest frequency character in a string.

20.Write a JAVA program to count frequency of each character in a string.

21.Write a JAVA program to remove first occurrence of a character from string.

22.Write a JAVA program to remove last occurrence of a character from string.

23.Write a JAVA program to remove all occurrences of a character from 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.

29.Write a JAVA program to find first occurrence of a word in a given string.

30.Write a JAVA program to find last occurrence of a word in a given string.

31.Write a JAVA program to search all occurrences of a word in given string.

32. Write a JAVA program to count occurrences of a word in a given string.


33.Write a JAVA program to remove first occurrence of a word from string.

34.Write a JAVA program to remove last occurrence of a word in given string.

35.Write a JAVA program to remove all occurrence of a word in given 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

e.g first string : abcd second string : dacb

42. WAP a JAVA program to print first non-repeated character from String?

43.WAP a JAVA program check if a String contains only digits?

44.WAP a JAVA Program count the occurrence of a given character in String?

45. How to find all permutations of 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".

47. How to check if String is Palindrome?

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.

48. How to check if a String is a valid shuffle of two String?

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.

49. How to return highest occurred character in a 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".

50. Write a program to find the longest palindrome in a string?

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.

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

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.

You might also like