If you want to get whether a string starts with a specified string, you can use the java.lang.String class's two overloaded startsWith() method. It returns true if the string contains the prefix or false otherwise.
In single argument startsWith() method, the only argument is the string that is the prefix in the specified string.
In two argument startsWith() method, the first argument is the prefix...
7.31.2014
7.30.2014
Math: min() - Returns the smaller of two numbers
In order to return the smaller of two numbers, java.lang.Math class provides four static overloaded min() methods. The min() method takes two numbers as arguments and return the greater of the two.
The four overloaded min() methods are for int, long, float and double.
Some points about the min() method is given below:
If the two arguments are same, the method returns the same value.
The method...
Math: max() - Returns the greater of two numbers
In order to return the greater of two numbers, java.lang.Math class provides four static overloaded max() methods. The max() method takes two numbers as arguments and return the greater of the two.
The four overloaded max() methods are for int, long, float and double.
Some points about the max() method is given below:
If the two arguments are same, the method returns the same value.
The method...
7.27.2014
Arrays: sort() – Sorts an array
In order to sort an array, java.util.Arrays class provides 18 overloaded sort() method for not only primitive types(excluding boolean) and Object, but also your custom sort implementation for your own objects.
For single argument (primitive types) sort() method, it sorts the specified array in ascending numerical order.
For three argument (primitive types) sort() method, the first argument is the...
7.26.2014
Arrays: toString() – Returns string representation of an array
Normally if
you want to get the string
representation of the contents of an array, you need to traverse the array
using loop constructs. But java.util.Arrays class provides nine overloaded
toString() methods to return the string representation of the contents of the
specified array which is passed as the only argument to the method.
The string
representation consists of a list of the array's...
7.25.2014
String: contains() - Checks whether a CharSequence is present in a String
If you want to
check whether a string contains a specified character sequence that implements
CharSequence interface (String, StringBuffer, StringBuilder), you can use
contains() method defined in java.lang.String class. This method takes a
character sequence as single argument and return true if the specified argument
is present in the string or false if it doesn’t.
Some critical
points to be...
Math: abs() - Returns the absolute value of a number
To get the
absolute value of a number, java.lang.Math class defines four static overloaded
abs() methods that takes an int or long or float or double as its only argument
and returns the absolute value of that passed argument.
The following
rules apply for this methods:
If the passed
argument is positive, then this method returns the argument.
If the passed
argument is negative, this method...
Subscribe to:
Posts (Atom)