Java tutorial-Java String Manipulation

Java String Manipulation

Java provides the String class that contains a lot of useful methods to operate on strings. For example, you can use Java string operations methods to find the length of a string, get a character in a specified index of a string, combine two strings, change cases of a string to lower case or upper case, find the position of a character or a  substring in another string, convert a string to an array of character, get a substring from a string, compare two strings, test a string whether it starts with or ends with a substring, and replace an existing substring with a new substring in a string. The Java string operation methods that can handle those such things can be length(), charAt(), concat(), toLowerCase, toUpperCase, indexOf(), toCharArray(), substring(), compareTo(), equals(), startsWith(), endsWith(), and replace() methods.


Dara comment


This code might help you:
String sen="I love Java";
String[] words=sen.split(" ");
String reverse="";
for(int i=words.length-1;i>=0;i--){
reverse=reverse+words[i]+" ";

Samorn comment


How can i reverse words in a text? For example, given the text "I love Java", the output will be "Java love I".


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.