compare two strings in java

Ads
 

compare two strings in java

How to compare two strings in java?

View Answers

July 4, 2012 at 7:05 PM

package Compare;

public class StringTest {
    public static void main(String [] args){

        String str="Roseindia";

            String str1="Roseindia";

          if (str.compareTo(str1) == 0)

           {

 System.out.println("The two strings are the same.");

        }

     }

  }

Output:

The two strings are the same.

Description:-Here is an example of comparing two strings. By using the method compareTo, we have compared strings. If the strings are exactly the same, the compareTo method will return a value of 0 (zero).

Ads









Related Tutorials/Questions & Answers:
compare two strings in java
compare two strings in java  How to compare two strings in java...) { System.out.println("The two strings are the same."); } } } Output: The two strings are the same. Description:-Here is an example of comparing two
How do I compare strings in Java?
How do I compare strings in Java?  How do I compare strings in Java
Advertisements
Java : String Compare
Java : String Compare This tutorial demonstrate various way to compare two strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two
Java : String Compare
Java : String Compare This tutorial demonstrate various way to compare two strings.  String Compare : In java, you can compare strings in many ways... the strings.  int compareTo( String anotherString ): This method compare two
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
Concatenating two Strings in Java
Concatenating two Strings in Java In this section we will help you, how to concatenate two strings in java. String are sequence of character which is used... that concatenate the two strings. String str1="hello"; String str2=" Java
java program to compare two hashmaps and check whether they are equal or not
java program to compare two hashmaps and check whether they are equal or not  java program to compare two hashmaps and check whether they are equal
Compare two word file
Compare two word file  How to compare two word file using Java
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
Concatenate Two Strings in java
Concatenate Two Strings in java We are going to describe how to concatenate of two string. we have use for concat() method, this method joints of two string... taken two String string and string2.This keyword returns of String followed
ModuleNotFoundError: No module named 'compare-strings-lib'
ModuleNotFoundError: No module named 'compare-strings-lib'  Hi, My... named 'compare-strings-lib' How to remove the ModuleNotFoundError: No module named 'compare-strings-lib' error? Thanks   Hi
ModuleNotFoundError: No module named 'compare-strings-lib'
ModuleNotFoundError: No module named 'compare-strings-lib'  Hi, My... named 'compare-strings-lib' How to remove the ModuleNotFoundError: No module named 'compare-strings-lib' error? Thanks   Hi
ModuleNotFoundError: No module named 'jatto-compare-version-strings'
ModuleNotFoundError: No module named 'jatto-compare-version-strings'  ...: No module named 'jatto-compare-version-strings' How to remove the ModuleNotFoundError: No module named 'jatto-compare-version-strings' error
ModuleNotFoundError: No module named 'jatto-compare-version-strings'
ModuleNotFoundError: No module named 'jatto-compare-version-strings'  ...: No module named 'jatto-compare-version-strings' How to remove the ModuleNotFoundError: No module named 'jatto-compare-version-strings' error
how to compare text in two jTextarea
how to compare text in two jTextarea  give some sample code
question about mixing two strings
question about mixing two strings  using java script we need to ask two strig and combine them like.. str1= helo str2= worl combined string= hweolrol
strings
strings  write a program in java to accept two strings as command line arguments and perform the following operations-: 1) compare the strings 2... is an example which accept two strings as command line arguments and perform
Comparing two dates in java
Comparing two dates in java In this example you will learn how to compare two dates in java.  java.util.Date provide a  method to compare two dates. The method which is used to compare the dates is "compareTo() "
C String Compare
C String Compare       In this section, you will learn how to compare two strings. You can see in the given example, the program prompts the user to enter the two strings one
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
strings in java
strings in java  please explain me the flow of this program..not able to execute correctly n wats the use of clone public class Strclone { public static void main(String args[]) { String s=new String("a"); String s1
Appending Strings - Java Tutorials
.style1 { text-align: center; } Appending Strings In java, the two... will compare the performance of these two ways by taking example. We will take three tasks to compare performance. For this we also crate a separate timer class
How to compare date in Java?
How to compare date in Java?  Hi, How to compare date in Java? Thanks   Hi, Check this example Date Comparison. Thanks
hash function for java strings
hash function for java strings  hash function for java strings   int hash=7; for (int i=0; i < strlen; i++) { hash = hash*31+charAt(i
strings
strings  difference between the strings in java and c
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' ...: ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' How to remove the ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' ...: ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' How to remove the ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders'
ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' ...: ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders' How to remove the ModuleNotFoundError: No module named 'compare_man_pages_from_two_folders
intersection of two java arrays
intersection of two java arrays  I am trying to figure out how to compare two arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two arrays into the third array but am
validation of strings using java function
validation of strings using java function  hi all, i am uploading data from csv file to data base where i took student id as string of length 6 char of the form abc123 will you please give me a function to validate this field
Java create new array of strings.
Java create new array of strings.  Java create new array of strings.   Example: public class StringArray { public static void main(String[] args) { String name[] = { "mandy", "Rixi", "Ron

Ads