w3resource logo


Java Programming Exercies

Java String : Exercises, Practice, Solution

Secondary Nav

Java String Exercises [31 exercises with solution]

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

4. Write a java program to count a number of Unicode code points in the specified text range of a String. Go to the editor

Click me to see the solution

5. Write a java program to compare two strings lexicographically. Go to the editor

Click me to see the solution

6. Write a java program to compare two strings lexicographically, ignoring case differences. Go to the editor

Click me to see the solution

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

Click me to see the solution

8. Write a Java program to test if a given string contains the specified sequence of char values. Go to the editor

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

11. Write a Java program to create a new String object with the contents of a character array. Go to the editor

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Sample Output :

Current Date and Time :                                                                                       
September 10, 2016                                                                                            
4:26 pm 

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Sample string of all alphabet: "The quick brown fox jumps over the lazy dog."

Click me to see the solution

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

Click me to see the solution

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

Sample string of all alphabet: "The quick brown fox jumps over the lazy dog."

Click me to see the solution

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

Click me to see the solution

23. Write a Java program to find whether a region in the current string matches a region in another string. Go to the editor

Click me to see the solution

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

Click me to see the solution

25. Write a Java program to replace each substring of a given string that matches the given regular expression with the given replacement. Go to the editor

Sample string : "The quick brown fox jumps over the lazy dog."

In the above string replace all the fox with cat.

Click me to see the solution

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

Click me to see the solution

27. Write a Java program to get a substring of a given string between two specified positions. Go to the editor

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

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

Click me to see the solution

Java Practice online





List of Exercises with Solutions :



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Python: How to call an external command in Python?

C#: Loops in c#

SQL: JOIN using more than 5 tables