#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    7
    Rep Power
    0

    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.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    7
    Rep Power
    0
    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.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348
    See the answer posted on the other forum where you posted this question.

IMN logo majestic logo threadwatch logo seochat tools logo