Home Discussion Discuss: Java Compare String (== operator)

  • String Comparison by equals method.Pankaj September 27, 2011 at 11:52 PM

    In this section if you set the string String string1 = "Hi"; String string2 = new String("Hi"); then again it will print : "The strings are unequal." just because of the reason that "==" operator compares two String objects, not their values, and both the objects (i.e. string1 & string2 are different by name and their address location), if we want to compare both the strings then we have to use equals() method as: public class stringmethod{ public static void main(String[] args){ String string1 = "Hi"; String string2 = new String("Hi"); if (string1.equals(string2)) { System.out.println("The strings are equal."); } else { System.out.println("The strings are unequal."); } } }

  • *suvatea October 10, 2011 at 6:24 AM

    this is not correct for reading strings from keyboard

  • ProgramesB.Rajesh February 22, 2012 at 11:35 AM

    Hi Sir i want to compare to Two Strings .out put will be comes below s1=abc s2=abq ans:s3=aabbcg. this type of examples iwant Sir please

  • java stringsazhar April 18, 2012 at 2:10 PM

    please give me the complete java strings with examples to prepare for an interview

  • Clarification About StringsDIVI HARI BABU CHOWDARY April 30, 2012 at 9:19 PM

    How to Gather Whole String given at the time of enters string as input by using Scanner object?????????? For Example Scanner sc=new Scanner(System.in); System.out.println("Please Enter a String"); String s=sc.next(); Output Please Enter a String Hi how are you? But it takes only "Hi". I need to take whole the String. How??????????

  • StringsHemanth June 23, 2012 at 10:18 AM

    strings are clearly understandable when we visit RoseIndia website thanks to rose india

  • can u help me with this~eppy azwan August 13, 2012 at 1:53 PM

    help me with this, dont know which line being the problem.. totally the output not show up.. import java.io.*; public class G2 { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String gender,res; System.out.println("Enter lines of text."); gender = br.readLine(); String f= "Female"; String m="Male"; if(gender == m){ System.out.println("male"); } else if(gender == f){ System.out.println("female"); } } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Tips and Examples

Java Compare String (== operator)
Java Compare String (== operator)       This section describes how two string references....  The following program uses this operator compare the two strings 

Java-Tutorials

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. It has provide ==operator, equals method and compareTo method to compare 

Java-Tutorials

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. It has provide ==operator, equals method and compareTo method to compare 

MySQL

Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using the % wild... 'Mysql Like Operator'. This section of tutorial lists  records or rows from 

SQL Tutorial

Mysql Like Operator
Mysql Like Operator       Mysql Like Operator is used to compare a part of string using... an example from 'Mysql Like Operator'.This section of tutorial lists  records 

Programming Tutorials

PHP Comparison Operator
Comparison Operator: It is another kind of operator supported by PHP, with this operator you can compare two variables, whether the variables are equal... .e.g. if we compare "23" (string data type) and 23 (integer data type 

Java Beginners

Compare String with given String arraylists.
Compare String with given String arraylists.  I have one String for example abcThirtyFour. i have two arraylists of string. one contains one, two.... i was thinking of comparing given string with both the arraylists. but, i 

Mobile Applications Questions

nsstring compare
nsstring compare  HI, How to compare two NSString objects? Give me code for nsstring compare. Thanks   Hi, You can use isEqualToString...{ //String is not equal } Thanks 

Java Tips and Examples

Compare string example
Compare strings example       In this section, you will learn how to compare two strings in java. The java lang package provides a method to compare two 

Tutorials

iPhone Compare String
Compare String Final application will look like:   In this tutorial will learn how to compare two string in iPhone using Comparestring...;     NSString *string 

Java Beginners

compare two strings in java
compare two strings in java  How to compare two strings in java?   package Compare; public class StringTest { public static void main(String [] args){ String str="Roseindia"; String str1 

Programming Tutorials

PHP String Operator
String Operator: In PHP there are only two operators are available for strings, first one is "." operator, and another is ".= " operator. Basically both does the same but with a little difference. First operator 

C Tutorials

C String Compare
C String Compare       In this section, you will learn how to compare two strings. You can see... by one. The library function gets() get the entered string from the console 

General

Type Comparison Operator
Type Comparison Operator       Java provides a run-time operator instanceof to compare a class and an instance of that class. This operator " instanceof" compares 

PHP Questions

PHP Concatenation Operator
PHP Concatenation Operator  Hi friends, Can any one guide me how to use the concatenation string operator in PHP 

PHP Tutorial

PHP Concatenation Operator
The only one string operator in PHP is concatenation operator (.) that is used for putting two string values together; e.g. <?php $txt1=“Hello...? If we look at the code above you see that we used the concatenation operator two 

Java Technology Tutorials

File Path compare in java
In this section, we will discuss how to compare pathname of two file for the equality... { public static void main(String[] args) { File file1 = new File("C:/Folder 

Programming Tutorials

Compare two buffer's content
Compare two buffer's content In this tutorial we will see how to create a buffer and put content into it and compare byte data of one buffer...;void main(String[] args) {     CharBuffer  

Core Java

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 

Programming Tutorials

Compare buffer to another object.
Compare buffer to another object. In this tutorial you will see how to compare... to compare buffer with another. This method returns 0, 1 or -1 which means...;CharBufferDemo {   public static void main(String 

General

Simple Assignment Operator
Simple Assignment Operator       Assignment operator is the most common operator almost used with all programming languages 

Core Java

Java "&" operator
Java "&" operator. In this section you will learn how to use "&" operator in java. Java provide six types of operators: among... in java. Bitwise operator work on bit and perform bit by bit operation 

General

String equalsIgnoreCase(String Str)
: anotherString - the String to compare other String.   Returns true... String equalsIgnoreCase(String Str)   ... explanation about the equalsIgnoreCase(String Str) method of String 

General

Assignment operator in java
Assignment operator in java Assignment operator is very common to almost all... the value to the variable lying on the left side. Java assignment operator... to be assigned to the variable to the left side. Assignment operator is also used 

JSP Interview Questions

how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ... that. but as you see, first query needs integer and second one needs string. i...;% try{ String v=request.getParameter("id"); int id 

Programming Tutorials

Compare two char array in java
Description: This tutorial demonstrate how to compare two character array are equal or not. The Arrays.equals(c1, c2) helps to compare it and return...;void main(String[] args) {     char[]  

Programming Tutorials

Using [] operator of EL with an Array
Using [ ] operator of EL with an Array   .... The [] operator is much more powerful than the dot, because it lets you access... an array as string then it can only store the string values. The length 

General

Operator Precedence
Operator Precedence       Operator Precedence : In Java, Operator Precedence is an evaluation.... When two operators share an operand then operator with the higher precedence 

General

JavaScript type of Operator
JavaScript type of Operator       The JavaScript type of operator returns the datatype... to show the use of type of Operator. The operator returns 'object' for the variable1 

Java Tips and Examples

Java XOR Operator
Bitwise XOR (exclusive or) "^" is a Java operator.... Following example will show how to use "^" operator in Java. XOR is a binary operator that is evaluated from left to right. Example of Java XOR 

DMCA.com