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.



Comments

Dara comment

 Dara

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]+" ";
}
System.out.println(reverse.trim());

12-17-2013
Samorn comment

 Samorn

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

12-17-2013
Name:
Comment:
Enter the text:
CAPTCHA image

....................................................................................................................Home | Forum | About | Contact
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.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.
Home Programming Web DB & App Questions Exercises Tips Programs FAQs Download About
Computer-Wbest
Popular Pages
You might like