Contain method to read array
I am trying to find a method to read an array like this.
Code :
String[] operators = {"+", "-"};
if(operation.contains(operators))
System.out.println("noob");
else
System.out.println("noobcake");
The contains method will not read from the array but it works when I use it like this,
Code :
if(operation.contains("/") || (operation.contains("divide") || (operation.contains("division") || (operation.contains("Divide") || (operation.contains("Division"))))))
System.out.println(total = firstnumber / secondnumber);
else
System.out.println("You didn't enter a Valid Operator");
but this uses a bunch of unnecessary space and would be easier to edit with an array.
So my question is what method can I use to read from the array and apply to this situation?
I started java a week ago, so I am just trying to get used to it, and write lots of test programs.
Re: Contain method to read array
Any help? I would really like to get my program going, I was searching the String API Docs and only saw things pertaining to char/string nothing about array/sting.
Re: Contain method to read array
Re: Contain method to read array
Why do you want to use an array in order to save just a couple of operators. Just use variables, and check if each variable is a valid operator.
Oscar Gómez
Engineer at PSL
PSL S.A. - CMMi 5 nearshore software development and outsourcing from Latin America - Home