how to compare two words in java

0 votes

Hey, I was trying to compare two words in java but I am not able to do that , Continuously I am getting an error.

public class Compare {

    public static void main(String args[])

    {

        String string1 ="Garments" ;

        String string2 = "Dog";

        

        

        System.out.println("Comparing " + string1 + " and " + string2

                           + " : " + string1==string2));

  
Aug 8, 2019 in Java by Dhanush
2,299 views

1 answer to this question.

0 votes

hey,

 I think in your code the function you used to compare the words its not right,

So you can check your code with .equals() function

  public static void main(String args[])

    {

        String string1 ="Garments" ;

        String string2 = "Dog";

        

        

        System.out.println("Comparing " + string1 + " and " + string2

                           + " : " + string1.equalsIgnoreCase(string2));

Thank you

answered Aug 8, 2019 by sampriti
• 1,120 points

edited Aug 8, 2019 by Kalgi

Related Questions In Java

0 votes
0 answers

how to compare two strings in java?

how to compare two strings in java? READ MORE

Nov 16, 2021 in Java by Naresh
• 210 points
631 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,140 points
2,576 views
0 votes
2 answers

How to concatenate two arrays in Java?

public <T> T[] concatenate(T[] a, T[] b) ...READ MORE

answered Jul 19, 2018 in Java by Sushmita
• 6,920 points
2,919 views
0 votes
1 answer

How to calculate the difference between two date instances in Java?

You can use Joda Time Library. Interval i ...READ MORE

answered May 4, 2018 in Java by Parth
• 4,640 points
976 views
+11 votes
13 answers

Default parameters of XMS and XMX in JVM

Run this code to see all the ...READ MORE

answered Nov 13, 2018 in Java by anonymous
402,930 views
0 votes
1 answer

How to add items in list at a time?

Hi Priyanka , I think this code snippet ...READ MORE

answered Aug 9, 2019 in Java by sampriti
• 1,120 points
2,399 views
0 votes
1 answer

What is $stateProvider in AngularJs?

Routing is just another way of fixing some content ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,840 points
2,775 views
0 votes
3 answers

Does Java support Default Parameters?

You can try this with method overloading. void ...READ MORE

answered Sep 21, 2018 in Java by Sushmita
• 6,920 points
6,966 views
0 votes
1 answer

How can I compare two integers properly?

Hi Divya, I hope this code snippet will ...READ MORE

answered May 31, 2019 in Java by sampriti
• 1,120 points
1,025 views
0 votes
2 answers

How do I get distinct element from list in java?

You should use a Set. it doesn't contain duplicates. If ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,223 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP