- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9321 Articles for Object Oriented Programming
![Manikanth Mani](https://www.tutorialspoint.com/assets/profiles/13524/profile/60_53242-1512705034.jpg)
258 Views
The StringBuffer and StringBuilder classes are used when there is a necessity to make a lot of modifications to Strings of characters.Unlike Strings, objects of type StringBuffer and String builder can be modified over and over again without leaving behind a lot of new unused objects.The StringBuilder class was introduced as of Java 5 and the main difference between the StringBuffer and StringBuilder is that StringBuilder’s methods do not thread safe (not synchronized).It is recommended to use StringBuilder whenever possible because it is faster than StringBuffer. However, if the thread safety is necessary, the best option is StringBuffer objects. Read More
![Manikanth Mani](https://www.tutorialspoint.com/assets/profiles/13524/profile/60_53242-1512705034.jpg)
543 Views
To perform a reverse toggle split the words of a string, reverse each word using the split() method, change the first letter of each word to lower case and remaining letters to upper case.Example Live Demoimport java.lang.StringBuffer; public class ToggleReverse { public static void main(String args[]){ String sample = "Hello How are you"; String[] words = sample.split(" "); String result = ""; for(String word:words){ StringBuffer s = new StringBuffer(word); word = s.reverse().toString(); String firstSub = word.substring(0, 1); String secondSub = word.substring(1); result = result+firstSub.toLowerCase()+secondSub.toUpperCase()+" "; } System.out.println(result); } }OutputoLLEH wOH eRA uOY
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
959 Views
Following are the various constructors provided by the StringBuffer class.S.N.Constructor & Description1StringBuffer()This constructs a string buffer with no characters in it and an initial capacity of 16 characters.2StringBuffer(CharSequence seq)This constructs a string buffer that contains the same characters as the specified CharSequence.3StringBuffer(int capacity)This constructs a string buffer with no characters in it and the specified initial capacity.4StringBuffer(String str)This constructs a string buffer initialized to the contents of the specified string.
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
38K+ Views
To find whether a given string contains a number, convert it to a character array and find whether each character in the array is a digit using the isDigit() method of the Character class.ExampleLive Demopublic class ContainsExample { public static void main(String args[]){ String sample = "krishna64"; char[] chars = sample.toCharArray(); StringBuilder sb = new StringBuilder(); for(char c : chars){ if(Character.isDigit(c)){ sb.append(c); } } System.out.println(sb); } }Output64
![Alankritha Ammu](https://www.tutorialspoint.com/assets/profiles/13523/profile/60_83090-1512649277.jpg)
661 Views
You can change the cases of the letters of a word using toUpperCase() and toLowerCase() methods.Split each word in the string using the split() method, change the first letter of each word to lower case and remaining letters to upper case.ExampleLive Demopublic class Sample{ public static void main(String args[]){ String sample = "Hello How are you"; String[] words = sample.split(" "); String result = ""; for(String word:words){ String firstSub = word.substring(0, 1); String secondSub = word.substring(1); result = result+firstSub.toLowerCase()+secondSub.toUpperCase()+" "; } System.out.println(result); } }OutputhELLO hOW aRE yOU
![Alankritha Ammu](https://www.tutorialspoint.com/assets/profiles/13523/profile/60_83090-1512649277.jpg)
2K+ Views
The java.lang.String.contains() method returns true if and only if this string contains the specified sequence of char values.ExampleLive Demopublic class Sample { public static void main(String args[]){ String str = "Hello how are you welcome to tutorialspoint"; String test = "tutorialspoint"; Boolean bool = str.contains(test); System.out.println(bool); } }Outputtrue
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
571 Views
StringBuffer class of the java.lang package provides reverse() method. This method returns a reverse sequence of the characters in the current String. Using this method you can reverse a string in Java.To reverse each word in a string you need to split the string, store it in an array of strings and reverse each word using the reverse() method of the StringBuffer class.ExampleLive Demoimport java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tutorials point"); System.out.println("buffer = " + buff); // reverse characters of the ... Read More
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
16K+ Views
StringBuffer provides a method with name reverse() one way to check for a palindrome isCreate a StringBuffer object by passing the required string as a parameter to the constructor.Reverse the contents of the object using the reverse() method.Convert the StringBuffer object to Sting using the toString() method.Now, compare the String and the reversed one, if true, the given string is a palindrome.ExampleLive Demopublic class StringPalindrome { public static void main(String args[]) { String myString = "anna"; StringBuffer buffer = new StringBuffer(myString); buffer.reverse(); String data = buffer.toString(); ... Read More
![Alankritha Ammu](https://www.tutorialspoint.com/assets/profiles/13523/profile/60_83090-1512649277.jpg)
1K+ Views
One way to do it to convert both strings to lower or upper case using toLowerCase() or toUpperCase() methods and test.ExampleLive Demopublic class Sample { public static void main(String args[]){ String str = "Hello how are you welcome to Tutorialspoint"; String test = "tutorialspoint"; Boolean bool = str.toLowerCase().contains(test.toLowerCase()); System.out.println(bool); } }Outputtrue
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
139 Views
The contains() method of String class returns true if and only if this string contains the specified sequence of char values.ExampleLive Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials point", str2 = "http://"; CharSequence cs1 = "int"; // string contains the specified sequence of char values boolean retval = str1.contains(cs1); System.out.println("Method returns : " + retval); // string does not contain the specified sequence of char value retval = str2.contains("_"); System.out.println("Methods returns: " + retval); } }OutputMethod returns : true Methods returns: false