-3

I have this currently (and much more) and want to make it so that if someone types something in from the array that isn't uppercase(it is currently all uppercase), then they can still order it.

if(food.equals(array[0])) {
    System.out.println("Here is your " + food + ".");
}
Jonik
  • 80,077
  • 70
  • 264
  • 372
Durnehviir
  • 56
  • 1
  • 8

4 Answers4

5

Use equalsIgnoreCase instead of equals.

exexzian
  • 7,782
  • 6
  • 41
  • 52
Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
3

Use

food.equalsIgnoreCase(array[0])

It's documented, in the String API.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0

Use equalsIgnoreCase() instead of equals()

Rakesh KR
  • 6,357
  • 5
  • 40
  • 55
0

The other way to go about this is to ensure that everything stored in your array is lowercase, then do food = food.toLowerCase(); before testing whether food.equals() something in your array.

If you had a very tight performance requirement for this part of your application, you might choose to run the comparison this way.

user1445967
  • 1,520
  • 4
  • 14
  • 30
  • 1
    Another possibility is to create a Food class that knows how to compare itself case insensitively (overriding equals and hashCode), and use that instead of strings. – David Conrad Dec 16 '13 at 19:00