![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 9326 Articles for Object Oriented Programming
![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)
560 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)
138 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
![Manikanth Mani](https://www.tutorialspoint.com/assets/profiles/13524/profile/60_53242-1512705034.jpg)
102 Views
The compareTo() method compares the Number object that invoked the method to the argument. It is possible to compare Byte, Long, Integer, etc.However, two different types cannot be compared, both the argument and the Number object invoking the method should be of the same type.ExampleLive Demopublic class Test { public static void main(String args[]) { Integer x = 5; System.out.println(x.compareTo(3)); System.out.println(x.compareTo(5)); System.out.println(x.compareTo(8)); } }Output1 0 -1
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
339 Views
To find weather a string is rotation of another, concat the first string to itself twice and find weatherExample Live Demopublic class Sample { public static void main(String args[]){ String str1 = "gala"; String str2 = "alag"; String s3 = str1+str1; if(s3.contains(str2)) { System.out.println("str1 is rotation of str2"); } else { System.out.println("str1 is not rotation of str2"); } } }
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
2K+ Views
You can capitalize words in a string using the toUpperCase() method of the String class. This method converts the contents of the current string to Upper case letters.Example Live Demopublic class StringToUpperCaseEmp { public static void main(String[] args) { String str = "string abc touppercase "; String strUpper = str.toUpperCase(); System.out.println("Original String: " + str); System.out.println("String changed to upper case: " + strUpper); } }OutputOriginal String: string abc touppercase String changed to upper case: STRING ABC TOUPPERCASE
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
7K+ Views
The replaceAll() method of the String class replaces each substring of this string that matches the given regular expression with the given replacement. You can remove white spaces from a string by replacing " " with "".ExampleLive Demoimport java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Hi how are you Welcome to Tutorialspoint.com"); System.out.print("Return Value :" ); System.out.println(Str.replaceAll(" ", "")); } }OutputReturn Value :HihowareyouWelcometoTutorialspoint.com
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
2K+ Views
The charAt() method of the String class returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.The indexOf(int ch, int fromIndex) method of the String class returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex, then the index of ... Read More