
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

4K+ Views
You can compare two strings using either the equals() method or the compareTo() method. Where, The equals() method compares this string to the specified object. The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. These two methods compare the given strings with respective to Case i.e. String with the different case are treated differently. Example The following example demonstrates the comparison of two strings using the equals() method − public class Sample{ public static void ... Read More

222 Views
You can concatenate two strings using the concat() method of the String class. This class concatenates the specified string to the end of this string.ExampleLive Demopublic class Test { public static void main(String args[]){ String str1 = "Krishna"; String str2 = "Kasyap"; System.out.println(str1.concat(str2)); } }OutputkrishnaKasyap

600 Views
Java String class provides different comparison methods namely:The compareTo() methodThis method compares two Strings lexicographically. This method returns a negative integer if current String object lexicographically precedes the argument string. a positive integer if current String object lexicographically follows the argument true when the strings are equal.Exampleimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials", str2 = "point"; // comparing str1 and str2 int retval = str1.compareTo(str2); // prints the return value of the comparison ... Read More

405 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

2K+ Views
Given a string and its substring(s) of length k, write a Java program to compare and find whether the substrings are equal or not. Substring is a small portion of characters from a large string. In Java, a String is a class that represents a contiguous block of characters. Using compareTo() Method The compareTo() method belongs to the String class of java.lang package. It compares two strings based on the Unicode value of each character contained in the strings. It returns 0 if the specified strings are equal. Example In this example, we are using the compareTo() method to ... Read More

372 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

855 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

7K+ 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

4K+ 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