0% found this document useful (0 votes)
14 views10 pages

String Practice Sheet-2

The document is a practice sheet containing 102 Java programming exercises focused on string manipulation. Tasks include retrieving characters, comparing strings, counting occurrences, and various transformations. It is designed for learners to enhance their skills in handling strings in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

String Practice Sheet-2

The document is a practice sheet containing 102 Java programming exercises focused on string manipulation. Tasks include retrieving characters, comparing strings, counting occurrences, and various transformations. It is designed for learners to enhance their skills in handling strings in Java.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

String Practice Sheet-2

1. Write a Java program to get the character at the given index within the
String.

2. Write a Java program to get the character (Unicode code point) at the given
index within the String.

3. Write a Java program to get the character (Unicode code point) before the
specified index within the String.

4. Write a java program to count a number of Unicode code points in the


specified text range of a String.

5. Write a java program to compare two strings lexicographically.

6. Write a java program to compare two strings lexicographically, ignoring


case differences.

7. Write a Java program to concatenate a given string to the end of another


string.

8. Write a Java program to test if a given string contains the specified


sequence of char values.

9. Write a Java program to compare a given string to the specified character


sequence.

10.Write a Java program to compare a given string to the specified string


buffer.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
11.Write a Java program to create a new String object with the contents of a
character array.

12.Write a Java program to check whether a given string ends with the
contents of another string.

13.Write a Java program to check whether two String objects contain the same
data.

14.Write a Java program to compare a given string to another string, ignoring case
considerations.

15.Write a java program to print current date and time in the specified format.

16.Write a Java program to get the contents of a given string as a byte array.

17.Write a Java program to get the contents of a given string as a character array.

18.Write a Java program to create a unique identifier of a given string.

19.Write a Java program to get the index of all the characters of the alphabet.

20.Write a Java program to get the canonical representation of the string


object.

21.Write a Java program to get the last index of a string within a string.

22.Write a java program to get the length of a given string.

23.Write a Java program to find whether a region in the current string


matches a region in another string.

24.Write a Java program to replace all the 'd' characters with 'f' characters.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
25.Write a Java program to replace each substring of a given string that
matches the given regular expression with the given replacement.
Sample string : "The quick brown fox jumps over the lazy dog.

In the above string replace all the fox with cat.

26.Write a Java program to check whether a given string starts with the contents of
another string.

27.Write a Java program to get a substring of a given string between two


specified positions.

28.Write a Java program to create a character array containing the contents of


a string.

29.Write a Java program to convert all the characters in a string to lowercase.

30.Write a Java program to convert all the characters in a string to uppercase.

31.Write a Java program to trim any leading or trailing whitespace from a given
string.

32.Write a Java program to find longest Palindromic Substring within a string.

33.Write a Java program to find the second most frequent character in a given string

34.Write a Java program to print all permutations of a given string with repetition.

35.Write a Java program to check whether two strings are interliving of a given
string. Assuming that the unique characters in both strings.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
36.Write a Java program to find Length of the longest substring without repeating
characters.

37.Write a Java program to print after removing duplicates from a given string.

38.Write a Java program to find first non repeating character in a string.

39.Write a Java program to divide a string in n equal parts.

40.Write a Java program to remove duplicate characters from a given string


presents in another given string.

41.Write a Java program to print list items containing all characters of a given
word.

42.Write a Java program to find the maximum occurring character in a string.

43.Write a Java program to reverse a string using recursion.

44.Write a Java program to reverse words in a given string

45.Write a Java program to reverse every word in a string using methods.

46.Write a Java program to rearrange a string so that all same characters


become d distance away.

47.Write a Java program to remove "b" and "ac" from a given string.

48.Write a Java program to find first non-repeating character from a stream of


characters.

49.Write a Java program to count and print all the duplicates in the input string.

50.Write a Java program to check if two given strings are rotations of each other.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
51.Write a Java program to match two strings where one string contains wildcard
characters.

52.Write a Java program to find the smallest window in a string containing


all characters of another string.

53.Write a Java program to remove all adjacent duplicates recursively from a


given string.

54.Write a Java program to append two given strings such that, if the concatenation
creates a double characters then omit one of the characters

55.Write a Java program to return a new string where the last two characters
of a given string, if present, are swapped.

56.Write a Java program to read a string and return true if it ends in "ng"

57.Write a Java program to read a string,if the string begins with


"red" or "black" return that color string, otherwise
return the empty string.

58.Write a Java program to read two strings append them together and return the
result. If the strings are different lengths, omit chars from the beginning of
longer string and make them equal length.

59.Write a Java program to read a string and an int n, return a string made of the
first and last n characters from the string.

60.Write a Java program to read a string and return true if "good" appears
starting at index 0 or 1 in the given string.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
61.Write a Java program to return true from a given string if the first two characters
in the string also appear at the end.

62.Write a Java program to read a string and if a substring of length two appears at
both its beginning and end, return a string without the substring at the beginning
otherwise, return the original string unchanged.

63.Write a Java program to read a string and return the string without the first
two characters.Except keep the first char if it is 'g' and keep the second char if
it is 'h'.

64.Write a Java program to read a string and if one or both of the first tow
characters is 'x', return without those 'x',otherwise return the string unchanged.

65.Write a Java program to read a string and returns after remove the # and its
immediate left and right characters.

66.Write a Java program to return the substring that is between the first and last
appearance of the substring 'toast' in the given string,or return the empty string if
substirng 'toast' does not exists.

67.Write a Java program to check whether a string is pq-balanced or not.A String is


pq-balanced if for all the p's in the string atleast one 'q' must exists right of the
p's.But 'q' before the 'p' makes the pq-balanced false.

68.Write a Java program to return true when either of the two given strings
appear at the end of the other string ignoring case sensitivity.

69.Write a Java program to return true if a given string contain the string 'pop', but
the middle 'o' also may other character.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
70.Write a Java program to return true if the given string contains an appearance
of 'abc' but not directly a period(.) and followed by.

71.Write a Java program to return whether a prefix string made of the first N
specific characters of the string appear somewhere else in the string.

72.Write a Java program to check whether a string 'abc' in the middle of a given
string. Here middle means the number of character to the left and right of the
substring 'abc' must differ by at most one.

73.Write a Java program to count how many times the substring 'life' present at
anywhere in a given string. Counting can also happen for the substring 'li?e',
any character instead of 'f'.

74.Write a Java program to repeat a specific number of characters for specific


number of times from the last of a string.

75.Write a Java program to return the given string after removing the 2nd
character from the substring of length three, starting with 'z' and ending with
'g'.

76.Write a Java program to check whether the character immediately before and
after of # is same in a given string.

77.Write a Java program to check whether the string 'red' and 'blue' appear in
same number of times in a given string.

78.Write a Java program to repeat every character twice in the original string.

79.Write a Java program to make a new string from two given string in such a way
that, each character of two string will come respectively.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
80.Write a Java program to make a new string made of p number of characters
from the first of a given string and followed by p-1 number characters till
the p is greater than zero.

81.Write a Java program to make a new string with each character of just before
and after of t-string whichever it appears in m-string. Assume that m-string and
non-empty t-string has given.

82.Write a Java program to return the number of triples in the given string. A
triple is a character appearing three times in a row in a string.

83.Write a Java program to check whether a z is happy or not. A 'z' is happy when
there is another 'z' immediately to its left or right.Return true if all the z's in the
given string are happy.

84.Write a Java program to return a string where every appearance of the lowercase
word 'is' has been replaced with 'is not'.

85.Write a Java program to return the sum of the numbers (may form more than
one digits), appearing in the string.

86.Write a Java program to return true if the number of appearances of 'the' and 'is'
anywhere in the string is equal.

87.Write a Java program to return a substring after removing the all instances
of remove string as given from the given main string.

88.Write a Java program to find the longest substring appears at both ends of a
given string.

89.Write a Java program to find the longest mirror image string at the both ends
of a given string.
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
90. Write a Java program to return the sum of the digits present in the given
string. If there is no digits the sum return is 0.

91.Write a Java program to return the string after removing all 'z' (except
the very first and last) from a given string.

92.Write a Java program to return a string with the characters of the index
position 0,1,2, 5,6,7, ... from a given string.

93.Write a Java program to check whether the first instance of 'z' is


immediately followed by another 'z' in a given string.

94.Write a Java program to return a new string using every characters of even
positions from a given string.

95.Write a Java program to check if a given string contains another string.


Return true or false.

96.Write a Java program to test if a given string contains only digits.

97.Write a Java program to test if a given string contains only digits.

98.Write a Java program to remove a specified character from a given string.

99.Write a Java program to sort in ascending and descending order by length of


the given array of strings.

Original unsorted colors: [Green, White, Black, Pink, Orange, Blue, Champagne,
Indigo, Ivory]

\Sorted color (descending order): [Champagne, Orange, Indigo, Green, White,


Black, Ivory, Pink, Blue]

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
Sorted color (ascending order): [Pink, Blue, Green, White, Black, Ivory, Orange,
Indigo, Champagne]

100. Write a Java program to count the occurrences of a given string in another
given string.

101. Write a Java program to concatenate a given string with itself of a given
number of times.

102. Write a Java program to counts occurrences of a certain character in a given


string.

STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in

You might also like