|
Page 12 of 14
The if-else statement is a conditional statement. It is used to execute
a statement or group of statements based on some condition. The general
format of the statement is given below: if(boolean_expression)
{statements;} else {statements;} The......[read more]
An array initializer is a list of values or expressions used to
simultaneously create and initialize the elements of an array. The
values contained in an array initializer are separated by commas and
placed within curly braces, i.e., between "{" and "}". When an array
initializer is used to......[read more]
All arrays in Java have a public final field known as length. This
field is used to find the number of elements that the array holds. Once
an array is created, its size can be obtained by using the length field
qualified by the array name along with a dot operator. For example, the
given......[read more]
Concatenation is the process of joining two or more strings. Strings can be joined in three ways:
+ operator
+= operator
concat function
Each of them is shown with an example as follows:
The + operator
The + operator can be used to concatenate the strings as follows:......[read more]
Generics is one of the features added to J2SE 5. It allows a Java
programmer to abstract over types. It is most useful with collections
such as Set and List. Collections are bound to contain a specific type
of object. Therefore, if a programmer tries to insert any element other
than the specified......[read more]
StringBuilder is a class, which is very similar to the StringBuffer
class. It is a new concept introduced in J2SE 5. Like the String and
the StringBuffer classes, it extends directly from the Object class.
The StringBuilder class can act as an alternative to StringBuffer in
places where the......[read more]
A for-each loop is an enhanced for loop. It used to iterate over arrays
and collections. This feature was added to Java to make the access and
retrieval of elements of arrays and collections faster. The syntax of a
for-each loop is as follows: for(type itrvar: collection) { }
where,......[read more]
In pass-by-reference, an object reference is passed to the calling
method. The object reference that is passed is a copy of the original
object reference and not the actual reference itself. Therefore, the
caller and the called method will have identical copies of the
reference. Hence, both of......[read more]
The Comparable interface is used to sort collections and arrays of
objects using the Collections.sort() and java.utils.Arrays.sort()
methods respectively. The objects of the class implementing the
Comparable interface can be ordered. The Comparable interface in the
generic form is written as......[read more]
A split() function was added to Java 1.4. It belongs to the String
class. It simplifies the task of breaking (splitting) a string into
substrings or tokens. As an argument to split(), a character (or a
blank space) is passed where the string is split. The signature of a
split function is as......[read more]
|