URL

Class Overview

A Uniform Resource Locator that identifies the location of an Internet
resource as specified by RFC
1738.

Parts of a URL

A URL is composed of many parts. This class can both parse URL strings into
parts and compose URL strings from parts. For example, consider the parts of
this URL:
http://username:password@host:8080/directory/file?query#ref:

Throws

Public Methods

Returns true if this URL equals o. URLs are equal if they have
the same protocol, host, port, file, and reference.

Network I/O Warning

Some implementations of URL.equals() resolve host names over the
network. This is problematic:

The network may be slow. Many classes, including
core collections like Map and Set expect that equals and hashCode will return quickly.
By violating this assumption, this method posed potential performance
problems.

Equal IP addresses do not imply equal content.
Virtual hosting permits unrelated sites to share an IP address. This
method could report two otherwise unrelated URLs to be equal because
they're hosted on the same server.

The network many not be available. Two URLs could be
equal when a network is available and unequal otherwise.

The network may change. The IP address for a given
host name varies by network and over time. This is problematic for mobile
devices. Two URLs could be equal on some networks and unequal on
others.

This problem is fixed in Android 4.0 (Ice Cream Sandwich). In that
release, URLs are only equal if their host names are equal (ignoring
case).

Parameters

o

the object to compare this instance with.

Returns

true if the specified object is equal to this Object; false otherwise.

public
int
hashCode()

Returns an integer hash code for this object. By contract, any two
objects for which equals(Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals
comparisons also changes.