String Practice Sheet-2
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.
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.
19.Write a Java program to get the index of all the characters of the alphabet.
21.Write a Java program to get the last index of a string within a 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.
26.Write a Java program to check whether a given string starts with the contents of
another string.
31.Write a Java program to trim any leading or trailing whitespace from a given
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.
41.Write a Java program to print list items containing all characters of a given
word.
47.Write a Java program to remove "b" and "ac" from a given string.
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.
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"
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.
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'.
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.
94.Write a Java program to return a new string using every characters of even
positions from a given string.
Original unsorted colors: [Green, White, Black, Pink, Orange, Blue, Champagne,
Indigo, Ivory]
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.
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in