URL equals Example

URL class equals example. This example shows you how to use equals method.


URL class equals example. public boolean equals(Object obj) Compares this URL for equality with another object. If the given object is not a URL then this method immediately returns false. Two URL objects are equal if they have the same protocol, reference equivalent hosts, have the same port number on the host, and the same file and fragment of the file.

Here is the code
/*
 * @ # Equals.java
 * A class repersenting use to Equals method 
 * of URL class in java.net package
 * version 23 June 2008
 * author Rose India 
 */

import java.net.*;

public class Equals {

    public static void main(String args[]) throws Exception {

        String str = "http://locathost:8080";
        URL url1, url2;
        url1 = new URL(str);
        url2 = new URL(str);

        System.out.println("url1 and url2 is equals "+url1.equals(url2));

    }
}

Output
url1 and url2 is equals true

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US