![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
![Ayyan](https://www.tutorialspoint.com/assets/profiles/13521/profile/60_79767-1512650417.jpg)
315 Views
You can concatenate strings using the ‘+’ operator of Java.ExampleLive Demopublic class Test { public static void main(String args[]){ String st1 = "Hello"; String st2 = "How"; String st3 = "You"; String res = st1+st2+st3; System.out.println(res); } }OutputHelloHowYou
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
944 Views
Following is an example which compares Strings and portion of strings in Java? Explain with an example.ExampleLive Demopublic class StringDemo { public static void main(String[] args) { String str1 = "tutorials point"; String str2 = str1.substring(10); int result = str1.compareTo(str2); // prints the return value of the comparison if (result < 0) { System.out.println("str1 is greater than str2"); }else if (result == 0) { System.out.println("str1 is equal to str2"); }else { System.out.println("str1 is less than str2"); } } }Outputstr1 is less than str2
![Anjana](https://www.tutorialspoint.com/assets/profiles/13774/profile/60_78029-1512648681.jpg)
251 Views
The concat() method of the String class concatenates the specified string to the end of this string.ExampleLive Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { // print str1 String str1 = "self"; System.out.println(str1); // print str2 concatenated with str1 String str2 = str1.concat(" learning"); System.out.println(str2); // prints str3 concatenated with str2(and str1) String str3 = str2.concat(" center"); System.out.println(str3); } }Outputself self learning self learning center
![Jai Janardhan](https://www.tutorialspoint.com/assets/profiles/13513/profile/60_63529-1512538711.jpg)
640 Views
When you store a String asString str1 = "Hello";directly, then JVM creates a String object with the given value in a separate block of memory known as String constant pool.And whenever we try to create another String asString str2 = "Hello";JVM verifies whether any String object with the same value exists in the String constant pool, if so, instead of creating a new object JVM assigns the reference of the existing object to the new variable.And when we store String asString str = new String("Hello");using the new keyword, a new object with the given value is created irrespective of the ... Read More
![Fendadis John](https://www.tutorialspoint.com/assets/profiles/13534/profile/60_64028-1512539837.jpg)
5K+ Views
The compareTo() method of the String class. This method compares two Strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. This method returnsa negative integer if current String object lexicographically precedes the argument string.a positive integer if current String object lexicographically follows the argumenttrue when the strings are equal.ExampleLive Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials", str2 = "point"; ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
3K+ Views
Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects. The Java platform provides the String class to create and manipulate strings. You can also create a String directly as − String greeting = "Hello world!"; A string literal should be enclosed in double quotes. Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'. Example Live Demo public class StringDemo { public static void main(String args[]) { ... Read More
![Akshaya Akki](https://www.tutorialspoint.com/assets/profiles/13526/profile/60_48621-1512703980.jpg)
108 Views
The concat() method of the String class concatenates the specified string to the end of this string.Exampleimport java.lang.*; public class StringDemo { public static void main(String[] args) { // print str1 String str1 = "self"; System.out.println(str1); // print str2 concatenated with str1 String str2 = str1.concat(" learning"); System.out.println(str2); // prints str3 concatenated with str2(and str1) String str3 = str2.concat(" center"); System.out.println(str3); } }Outputself self learning self learning center
![Sai Nath](https://www.tutorialspoint.com/assets/profiles/13525/profile/60_63072-1512539005.jpg)
179 Views
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.ExampleLive Demopublic class Sample { public static void main(String []args) { String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }Outputtrue falseYou can also compare two strings using == operator. But, it compares references to the given ... Read More
![Moumita](https://www.tutorialspoint.com/assets/profiles/13507/profile/60_122499-1557898491.jpg)
1K+ Views
You can create a String by -Assigning a string value wrapped in " " to a String type variable.String message = "Hello Welcome to Tutorialspoint";Creating an object of the String class using the new keyword by passing the string value as a parameter of its constructor.String message = new String ("Hello Welcome to Tutorialspoint");Passing a character array to the String constructor.char arr[] = {'H','e','l','l','o'}; String message = new String(arr);