java string comparison example

java string comparison example

how to use equals method in String Comparison?

View Answers

July 4, 2012 at 7:17 PM

package Compare;

public class StringTest {
    public static void main(String [] args){
        String str="Rose";
        String str1="ROSE";
        if (str.equals(str1))
        {
         System.out.println("The two strings are same.");
        }
            else{
              System.out.println("The two strings are not same.");
        }
    }

}

Output:

The two strings are not same.

Description:-Here is an example of comparing two strings using equals() method. In the above example, we have declared two string and using the method equals(), we have compared the strings. This method is case sensitive.


July 5, 2012 at 12:58 PM

and if u want to compare two strings not evn caring whats the case of both strings being compared....then there is method in java called str.equalsIgnoreCase(str1) which will return a boolean having value true here in above example..

e.g.-->

public class StringTest { public static void main(String [] args) { boolean b=false; String str="Rose"; String str1="ROSE"; b= str.equalsIgnoreCase(str1)

   System.out.println("The two strings are same-->"+b);


}

}









Related Tutorials/Questions & Answers:
java string comparison example
java string comparison example  how to use equals method in String Comparison?   package Compare; public class StringTest { public... using equals() method. In the above example, we have declared two string
String Comparison - Java Interview Questions
String Comparison  How to compare string in Java?  Hi... static void main(String[] args) throws IOException{ BufferedReader buff = new... the first string !"); String str = buff.readLine(); System.out.println
Advertisements
String comparison example
.style1 { font-size: medium; } String comparison example:- There are many comparison operators for comparing strings like <, <... for each character in the string. In the Action script3, every comparison
java comparison
java comparison   TABLE 1 TABLE 2 column 1column 2column 3 column 1 column 2 column 3 1 10 A 22 25 A 2 20 B 25 25 B 3 30 G... the java code to solve this table matching
Example of appending to a String
Example of appending to a String  Hi, Provide me the example code of appending to a Java program. Thanks   Hi, Check the tutorial: How To Append String In Java? Thanks
Comparison between the types of sorting in java
Comparison between the types of sorting in java  welcome all i wanna program in java compare between selection,insertion,bubble,merge,quick sort In terms of timer and put all types in frame and find the timer for example array
String Reverse In Java Example
String Reverse In Java Example In this tutorial we will read about reversing a String in Java. Here we will see how a String can be represented in its... will create a Java class where we will define a String constant, and then we
How to Append String In Java?
the StringBuilder class. Check the example at Appending String in java. You can...How to Append String In Java?  How to write program in in Java for appending to a String? How to Append String In Java? What is the best way to do
Java String Split Example
Java String Split Example In this section, you will learn how to split string into different parts using spit() function. CODE In the given below example, the first string splits where the compiler finds the delimiter '-'
Java String To Date
string will be convert into Java date object. In this example we will first...Java String To Date In this section you will read about how to convert... be convert into java.util.Date. Java string to date convert explains
Character Comparison Example
Character Comparison Example     ... in Java. The java.lang package provides a method for comparing two case... value. If it will return '0' it means the given string is equal otherwise not equal
Reverse String Program in Java
Reverse String Program in Java We are going to describe about reverse string program in java. In this example reverses a string entered by the user. We... on String handling in Java: Java insertion sort with string array
XML to DB2 Comparison using Java xpath
XML to DB2 Comparison using Java xpath  Hi , I am a manual tester...' products . i want to compare these xml values with db2 using Java. I have Good knowledge in C, C++ and Ok with java. I am planning to use xpath to get details
Converting a String to Integer in Java
Converting a String to Integer in Java In this video tutorial I will show you how to convert a String value to Integer in Java? The easiest way to convert.... Here is the video tutorial of "How to convert String to Integer in Java
Compare string example
_package>java CompString String equals or not example! Please enter...:\vinod\Math_package>java CompString String equals or not example... Compare strings example     
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
converting string to double in java
converting string to double in java  Please post an example to converting string to double in java. Thanks!   Convert String to Double Tutorial
Java Comparison
Java Comparison       Java Vs Script The Java  and Java Script are completely different from each other although posses same name but don't have
String Start with Example
String Start with Example       In this section, you will learn how to check the given string... StrStartWith String start with example! Given String : Welcome to RoseIndia
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we.... In the given below example, you can see the difference in the creation time :ADS... main(String[] args) { testMultiArray(); testMultiArray2(); testSingleArray
Java String
with running example to Java String: http:/www.roseindia.net/java/string-examples/ ... Java String       In this section, you will learn about the java string. Java String is a set
Appending String efficiently in Java
example at How To Append String In Java? Thanks...Appending String efficiently in Java  Hi, Share me the example code for Appending String efficiently in Java. Thanks   Hi, StringBuilder
string - Java Beginners
Converting into String in Java  Need an example of Converting into String in JavaThanks in Advance
String End with Example
C:\vinod\Math_package>java StrEndWith String end with example... String End with Example       This section tells you, how to determine the given string ends
How To Append String In Java
How To Append String In Java In this section we will read about how to append String in Java. Here we will see the solution of this question through a simple example. There are various ways to append String in Java. Below, we
Java char to string
of any white space.ADS_TO_REPLACE_1 Example of converting Java char to string...Following program will show you how to convert a char into a string in Java. Though there are many ways to convert a char to a string we will use toString
How to convert String Date to Timestamp in Java?
String Date to Timestamp example in Java Java is programming language.... In this example program we are going to convert String representation of Date object... java.util.Date; /* * Web: http://www.roseindia.net * Example of Converting String
Java 11 String lines function example to split it in lines
Java 11 String lines function - How to split String into lines in Java 11.... In this version of Java (JDK 11) String class introduces a new method...-line string very frequently. Today I am trying lines() method of Java 11
Java 11 String lines function example to split it in lines
of Java 11 to split multi-line string. Here is the full example code: import...Java 11 String lines function - How to split String into lines in Java 11.... In this version of Java (JDK 11) String class introduces a new method
java programmming: string manipulation
' occurring in it   Here is a java example that reads a string from the command prompt and find the frequency of the character e in the input string...java programmming: string manipulation  WAP to accept a string from
Java String
Java String  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon as possible Thank you
String - Java Interview Questions
Java String array declaration and initialization  I am looking for an example of java string array declaration and initialization  Hipublic class ImmutableCart { private final List items; public ImmutableCart(List
comparison with null - Framework
comparison with null  String value = txtfld.getText(); if (value == null) ----- failing step----control goes to else part { // some code } else { // some code } Here comparison is not done.   Hi
Date comparison in PHP - PHP
Date comparison in PHP  I am looking for a date comparison code in PHP that can compare the date in between two different date formate.. for example: 11/12/1999 and 11/12/2001 to 11.11.1888 00:00:00 any idea on how
image comparison - Java Beginners
Java char to string
There are many ways to convert a char into a string in Java, one of them... it into substrings consisting of any white space. Example of converting char to string using...: Convert Character into a String Java char to string
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
String length example
C:\vinod\Math_package>java StringLength String lenght example... String length example     ... of given string. The lang package of java provides the facility for getting
Comparison of corresponding rows in a DB
Comparison of corresponding rows in a DB  How to compare corressponding rows in a database using Java????? ex...!!! Thankin u
Convert ASCII to string
Description: This tutorial demonstrate how to convert ASCII to string .  Code:ADS_TO_REPLACE_1 public class IntToChar{   public static void main(String[] args) 
String and StringBuffer - Java Beginners
String and StringBuffer  Dear Deepak Sir, What is String and StringBuffer.Give an example with explanation. Thanks & Regards, VijayaBabu.M  Hi vijay Java provides the StringBuffer and String classes
string
"This is example of java Programme" and also display word that contain "a" character.   Here is a java example that accepts a sentence from the user... String_Example { public static void main(String[] args
Date comparison
Date comparison  Hi..i have developed an application in which i pop up a message by comparing the dates.the comparison is done by the current date and the date previously stored in the database.the database value is first
string - Java Beginners
string in java interview questions  What is string in java? Interview questions
capitalizing string in java
capitalizing string in java  How to capitalizing string in Java?   String s = "some string"; String capitol = Character.toString(s.charAt(0)).toUpperCase(); String newString = capitol + s.substring(1,x
String substring method example
.style1 { font-size: medium; } String substring() method example... string. In this example we have used this method. Example:-ADS_TO_REPLACE_1... a string. String class provide methods for finding substring from string. Method

Ads