Java Practice Exercise – String Handling

  • Read a string
    • Check for empty string
    • Display string length
    • Display reverse of a string
    • Character at a given position
    • Index of a substring in a string
    • Join a list of strings
    • Copy first n characters
    • Copy last n character
    • Split a string based on the spaces / delimiter
    • Copy n characters from mth position
    • Convert all characters to uppercase
    • Convert all characters to lower case
    • Replace a character
    • Delete a character
    • Count number of vowels
  • Convert string to character array and vice versa
  • Read a String and display the ASCII value of each character in string
  • Read a string and a character and display the first and last occurrence of character in string.
  • Check if given character is upper case / lower case / digit / special character
  • Count number of upper, lower, digit and special character
  • Read a string and classify characters as upper case / lower case / digit / special character.
  • Read a string and display total number of upper case / lower case / digit / special characters in it
  • Sort an array of strings
  • Read a string and sort the words alphabetically
Example:
Input:      EEE IT MECH AUTO CSE
Output:   AUTO CSE EEE IT MECH
  • Write a Java Program that reads a line of integers, and then displays each integer, and the sum of all the integers (use StringTokenizer class)
  • Read an array of strings and display the sets of anagrams.
  • Write a Java program for sorting a given list of names in ascending order
  • Write a program to check if a given string is a palindrome or not.
  • Write a program to count and display the number of capital letters in a given string.
  • Write a program to count the number of vowels in a string.
  • Write a program to display the number of times each vowel occurs in a string. (ignore case)
  • Write a program to remove all punctuations and special characters (~!@#$%^&*()_{}[]\:”;’<>?,./) in a given string.
  • Write a java program that reads a string from inputs containing first name, last name and computes an e-mail address with first 3 letters of the first name, first 4 letters of last name, ‘.’ separator and domain. Display the outputs by invoking objects.
  • Write a program to accept a string and display the resultant string in a reverse order. The resultant string should contain all characters at the even position of accepted string ignoring blank spaces.
Example:
Given string: An apple a day keeps the doctor away
Required output: ywrtoetpeydepaA
  • Given a string containing both upper and lower case letters, write a python program to count the number of repeated characters and display the maximum count of a character along with the character
Sample input: ABaBCbGc
Output:
                           2A
                           3B
                           2C
                           1G
                           B is repeated 3 times
  • Consider 2 strings string1 and string2 and display the merged_string as output. The merged_string should be capital letters from both the strings in the order they appear.
Sample Input:
String1: I Like Java
String2: Mary Likes Python
merged_string: ILJMLP