Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
I have two textbox one is named adminname and other is adminpassword. I want to get input from these two text box and use in if condition but i am not getting the result
here is my Code
String name=adminname.getText();
        String password=adminpassword.getText();
        if(name="anoop" && password="sharma")
        {
            JOptionPane.showMessageDialog(rootPane, "Login successfull");
        }
Please Help me in finding my mistake/error.
Thanx in advance
Posted 26-May-13 2:00am
Comments
ThePhantomUpvoter at 26-May-13 8:05am
   
You need to use equals() to test strings for equality in java.
Anoop Kr Sharma at 26-May-13 8:09am
   
@ThePhantomUpvoter can you help me in creating the code using equals()
ThePhantomUpvoter at 26-May-13 8:15am
   
You are kidding right? You are seriously unable to to write if(name.equals("anoop")?
Anoop Kr Sharma at 26-May-13 8:22am
   
Thanx ThePhantomUpvoter for solving my problem
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

if(new String("test").equals("test")) 
{
  // Expression is true
}
 
if(new String("test") == "test")
{
  // Expresson is false since you are not comparing 
  // the same instance of the object to itself
}
 
 
Best regards
Espen Harlinn
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 5-Jun-13 23:08pm
   
Sure, a 5. —SA
Espen Harlinn at 6-Jun-13 10:21am
   
Thank you, Sergey :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In Java, '=' is not a comparison operator but assignment. For comparison, you need to replace it with '=='.
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 490
1 Sergey Alexandrovich Kryukov 316
2 Shai Vashdi 264
3 OriginalGriff 250
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,185
1 OriginalGriff 5,315
2 Peter Leow 4,040
3 Maciej Los 3,535
4 Abhinav S 3,308


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 27 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid