-6
if (key.equals ("1") || key.equals ("Circle")){

how can i make this statement true even if I enter the string "CiRcle" or "circle"? I mean at different cases.

4 Answers4

1

You can try as below :

if (key.equals ("1") || key.equalsIgnoreCase("Circle")){

More about equalsIgnoreCase

Butani Vijay
  • 4,181
  • 2
  • 29
  • 61
1
if (key.equals("1") || key.equalsIgnoreCase("Circle")){
Nailgun
  • 3,999
  • 4
  • 31
  • 46
0

The general syntax is

public boolean equalsIgnoreCase(String anotherString)

This method returns true if the argument is not null and the Strings are equal, ignoring case; false otherwise.

For your case

if (key.equals("1") || key.equalsIgnoreCase("Circle"))

Doc

Vignesh Vino
  • 1,242
  • 4
  • 25
  • 50
0

You can try

if (key.equals ("1") || key.equalsIgnoreCase ("Circle"))

However it seems like you did not have any research or studied String methods in java. I recommend you to look at String topic in java

Sami
  • 490
  • 6
  • 29