Home Answers Viewqa Java-Beginners java string comparison example

 
 


Naulej kumar
java string comparison example
2 Answer(s)      10 months ago
Posted in : Java Beginners

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 Pages:
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
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
String Comparison
Java NotesString Comparison Strings can not be compared with the usual <, <=, >, or >= operators, and the == and != operators don't compare... for unequal comparisons. For example, String s = "something", t = "maybe
Comparison Operators
Java NotesComparison Operators All the standard comparison operators work...) is not equal to 0.3! For C/C++ Programmers The Java comparison operators... object values. Operators The result of every comparison is boolean (true
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
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
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...; private final static int THE_OTHER_DIM = 4; public static void main(String
Date Comparison
program: C:\Examples>java DateComparison Comparison... Date Comparison       In this section we are discussing the comparison of two dates
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
PHP Comparison Operator
Comparison Operator: It is another kind of operator supported by PHP... .e.g. if we compare "23" (string data type) and 23 (integer data type... because of the dissimilarity of data type. Another way of comparison could
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
Java: Example - String sort
Java: Example - String sort Sorting is a mechanism in which we sort the data... the string. The example given below is based on Selection Sort. The Selection sort...() // Sort a String array using selection sort. void sort(String
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
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
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
Comparison Operators
how to use comparison operator : Example : <?php $a=3; $b=21; $c=30...Comparison Operators Operator is used to perform operation on variable and values. Comparison Operators are used to compare two values. Given below
Hibernate case sensitive comparison.
Hibernate case sensitive comparison.  How to check for case sensitive in Hibernate criteria?   package net.roseindia.main; import... CaseSensitiveComprision{ public static void main(String[] args
Mysql Date Comparison
of comparison between any two values of dates. Understand with Example The Tutorial illustrate an example from 'Mysql Date Comparison'. To understand... Mysql Date Comparison      
Java Compare String (== operator)
Java Compare String (== operator)       This section describes how two string references are compared. If two String variables point to the same object then these two
Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions.
, BETWEEN expressions, IN expressions, LIKE expressions, and comparison..., BETWEEN expressions, IN expressions, LIKE expressions, and comparison..., comparison operations, logical operations, path expressions that evaluate
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
string
string   difference detween "public static void main (String[] args) " and "public static void main (String args[])" in java but it executes both ,in java which one is legal   The only difference is style, where
String End with Example
String End with Example       This section tells you, how to determine the given string ends... StrEndWith String end with example! Given String : Welcome
string
string  java prgm to find total occurence of a given string pattern in a sentence
string
string  java prgm to find total occurence of a given string pattern in a sentence
String
String  How to Convert sunnapu gopal to Sunnapu Gopal in java using String
string
string   just i want to a program in a short form to the given string in buffered reader for example input string: Suresh Chandra Gupta output: S. C. Gupta   Here is your Example: package RoseIndia; import
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
Type Comparison Operator
Type Comparison Operator       Java provides a run-time operator instanceof to compare a class... as: object  instanceof  type Lets have an example
string
string  a java program using string function that computes your... links: http://www.roseindia.net/tutorial/java/core/printInitials.html http://www.roseindia.net/answers/viewqa/Java-Beginners/13383-print-initials.html
string
string  how do i extract words from strings in java???   Hi... ExtractWords { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter String
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
Java String
Java String       In this section, you will learn about the java string. Java String is a set... to a string literal in the object stream. The Java String object contains a sequence
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  how we conunt the no. of words in java without using in pre defined method in java
string
string  a java program to replace all matching substrings
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4
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
string - Java Beginners
Converting into String in Java  Need an example of Converting into String in JavaThanks in Advance
Compare string example
String equals or not example! Please enter first string: Rose... String equals or not example! Please enter first string: Rose... Compare strings example     
Java String Occurrence in a String
Java String Occurrence in a String   ... of a String in another String. Here we have already taken a String. Description of the code: In the program code given below, we will find another String
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
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 '-'
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
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
String length example
_package>java StringLength String lenght example! Please enter string... String length example     ... of given string. The lang package of java provides the facility for getting
Example - Array to String
Java: Example - Array to String Here is a simple, but slow, program to concatenate all of the strings in an array, each separated by a specifed string...() // Convert an array of strings to one string. // Put the 'separator' string
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.