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 2 of 2

Thread: Help writing if statement for two equal arrays

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help writing if statement for two equal arrays

    I need to write a if statement that checks if two arrays are equal and then performs some task.

    i.e.

    if java.util.Arrays.equals(data1, data2) = true

    then

    { do something }

    else if java.util.Arrays.equals(data1, data2) = false

    {do something else}

    thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help writing if statement for two equal arrays

    Did you look at the Arrays class to see if it has a method to compare the contents of two arrays?

    If not, you will have to write your own method to do the comparison.

    if java.util.Arrays.equals(data1, data2) = true)

    You'll need to use the == operator to compare things. = is the assignment operator
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    tuathan (July 6th, 2012)

Similar Threads

  1. Help writing the IF statement for Y/N
    By limeleaf in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 9th, 2012, 06:50 AM
  2. Why does this equal that?
    By colerelm in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 27th, 2011, 06:20 PM
  3. [SOLVED] Writing a program with arrays and class methods... PLEASE HELP?
    By syang in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 8th, 2011, 07:02 AM
  4. string.equals(anotherString) Anything like this for doesn't equal?
    By Andyandhisboard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2011, 06:50 PM
  5. While JOptionPane equal Yes????
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2010, 08:57 PM

Tags for this Thread