Java Tutorials
271. valueOf() in Java
By: Emiley J : 2007-09-02
Description: The valueOf() method converts data from its internal format into a human-readable form. It is a static method that is overloaded within String for all of Java's built-in types, so that each type can be converted properly into a string. valueOf() is also overloaded for type Object, so an object of any class type you create can also be used as an argument. (Recall that Object is a superclass for all classes.)
272. substring() in Java
By: Fazal : 2007-09-02
Description: You can extract a substring using substring(). It has two forms.
273. indexOf() and lastIndexOf() in Java
By: Hong : 2007-09-02
Description: These two methods are overloaded in several different ways. In all cases, the methods return the index at which the character or substring was found, or 1 on failure.
274. How to use equals() and equalsIgnoreCase() in Java
By: Fazal : 2007-09-02
Description: The comparison using equals() is case-sensitive. To perform a comparison that ignores case differences, call equalsIgnoreCase(). When it compares two strings, it considers A-Z to be the same as a-z. It has this general form:
275. How to use regionMatches() in Java
By: Mashoud : 2007-09-02
Description: The regionMatches() method compares a specific region inside a string with another specific region in another string. There is an overloaded form that allows you to ignore case in such comparisons. Here are the general forms for these two methods:
276. startsWith() and endsWith() in Java
By: Mashoud : 2007-09-02
Description: String defines two routines that are, more or less, specialized forms of regionMatches(). The startsWith() method determines whether a given String begins with a specified string. Conversely, endsWith() determines whether the String in question ends with a specified string. They have the following general forms:
277. equals() Versus == in Java
By: Mashoud : 2007-09-02
Description: It is important to understand that the equals() method and the == operator perform two different operations. As just explained, the equals() method compares the characters inside a String object. The == operator compares two object references to see whether they refer to the same instance. The following program shows how two different String objects can contain the same characters, but references to these objects will not compare as equal:
278. compareTo() in Java
By: Mashoud : 2007-09-02
Description: Often, it is not enough to simply know whether two strings are identical. For sorting applications, you need to know which is less than, equal to, or greater than the next. A string is less than another if it comes before the other in dictionary order. A string is greater than another if it comes after the other in dictionary order. The String method compareTo() serves this purpose.
279. Extract characters in Java
By: Hong : 2007-09-02
Description: The String class provides a number of ways in which characters can be extracted from a String object. Each is examined here. Although the characters that comprise a string within a String object cannot be indexed as if they were a character array, many of the String methods employ an index (or offset) into the string for their operation. Like arrays, the string indexes begin at zero.
280. String Conversion and toString() in Java
By: Mashoud : 2007-09-02
Description: When Java converts data into its string representation during concatenation, it does so by calling one of the overloaded versions of the string conversion method valueOf() defined by String. valueOf() is overloaded for all the simple types and for type Object. For the simple types, valueOf() returns a string that contains the human-readable equivalent of the value with which it is called. For objects, valueOf() calls the toString() method on the object. We will look more closely at valueOf() later in this chapter. Here, let's examine the toString() method, because it is the means by which you can determine the string representation for objects of classes that you create.