Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Comparing Arrays 
 

This section show you how to determine the given arrays are same or not.

 

Comparing Arrays : Java Util

                         

This section show you how to determine the given arrays are same or not. The given program illustrates you how to compare arrays according to the content of the that.

In this section, you can see that the given program initializes two arrays and input five number from user through the keyboard. And then  the program checks whether the given taken both arrays are same or not. This comparison operation is performed by using the equals() method of Arrays class.

Arrays.equals():
Above method compares two arrays.

Arrays is the class of the java.util.*; package. This class and it's methods are used for manipulating arrays.

Here is the code of the program:

import java.io.*;
import java.util.*;

public class ComparingArrays{
  public static void main(String[] argsthrows IOException{
    int[] array1 = new int[5];
    int[] array2 = new int[5];
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    try{
      System.out.println("Enter 5 numbers for the first Array : ");
      for(int i = 0; i < array1.length; i++){
        array1[i= Integer.parseInt(in.readLine());
      }
      System.out.println("Enter 5 numbers for the second Array : ");
      for(int i = 0; i < array2.length; i++){
        array2[i= Integer.parseInt(in.readLine());
      }
    }
    catch(NumberFormatException ne){
      ne.printStackTrace();
    }

    boolean check = Arrays.equals(array1, array2);
    if(check == false)
      System.out.println("Arrays are not same.");
    else
      System.out.println("Both Arrays are same.");
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c string ide class reference io references size sed get vi key value field fields this id length max preferences

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

nice site for student and devloper

Posted by umakanta p on Wednesday, 05.28.08 @ 14:36pm | #61267

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.