Program to perform Bubble Sort on Strings

Bubble Sort on Strings example In the following example we have stored the strings in a String array and we are using nested for loops to compare adjacent strings in the array, if they are not in order we are swapping them using a temporary string variable temp. Here we are using compareTo() method to compare the adjacent Strings. Output:

Program to reverse words in a String

 Program to reverse every word in a String using methods In this Program, we first split the given string into substrings using split() method. The substrings are stored in an String array words. The program then reverse each word of the substring using a reverse for loop. Output:

Convert Char To String and a String to char

rogram to convert char to String We have following two ways for char to String conversion.Method 1: Using toString() methodMethod 2: Usng valueOf() method Output: Converting String to Char We can convert a String to char using charAt() method of String class. Output: