Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Contain method to read array

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Contain method to read array

    I am trying to find a method to read an array like this.

    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,

    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
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Contain method to read array


  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

Similar Threads

  1. Contain method to read array
    By theaveguy in forum Java Theory & Questions
    Replies: 8
    Last Post: February 25th, 2012, 01:53 PM
  2. Replies: 0
    Last Post: June 19th, 2011, 02:16 AM
  3. Read in file and store in 2D array start of The Game of Life
    By shipwills in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2011, 08:52 AM
  4. Read A File and Store Values into a 2-Dimensional Integer Array?
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 08:13 PM
  5. NullPointerException when trying to read Strings into an array of myObject
    By sdivinyi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 24th, 2010, 09:45 AM