- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 593 Articles for Java Programming

Updated on 23-Jun-2020 15:23:49
The java.util.LinkedList.listIterator(int index) method returns a list-iterator of the elements in this list (in proper sequence), starting at the specified position in the list.DeclarationFollowing is the declaration for java.util.LinkedList.listIterator() methodpublic ListIterator listIterator(int index)Parametersindex − index of the first element to be returned from the list-iteratorReturn ValueThis method returns a ListIterator of the elements in this list (in proper sequence), starting at the specified position in the listExceptionIndexOutOfBoundsException − if the index is out of rangeExampleThe following example shows the usage of java.util.LinkedList.listIterator() method.Example Live Demopackage com.tutorialspoint; import java.util.*; public class LinkedListDemo { public static void main(String[] args) { ... Read More 
Updated on 23-Jun-2020 15:24:33
Optional is a container object used to contain not-null objects. Optional object is used to represent null with absent value. This class has various utility methods to facilitate code to handle values as 'available' or 'not available' instead of checking null values. It is introduced in Java 8 and is similar to what Optional is in Guava.Class DeclarationFollowing is the declaration for java.util.Optional class −public final class Optional extends ObjectClass MethodSr.No.Method & Description1static Optional empty()Returns an empty Optional instance.2boolean equals(Object obj)Indicates whether some other object is "equal to" this Optional.3Optional filter(PredicateRead More 
Updated on 23-Jun-2020 15:25:56
instanceof operator is used to check the type of object passed. Following rules explain the usage of instanceof operator in Java.instanceof operator returns true for the object if checked against its class type.instanceof operator returns false for the object if checked against its type which is not in its hierarchy.instanceof operator returns true for the child object if checked against parent object type.instanceof operator returns true for the complete object hierarchy up to the Object class.instanceof operator returns false for the null value.instanceof operator returns false for the parent object if checked against child object type.Following example showcases the above ... Read More 
Updated on 23-Jun-2020 15:27:23
Java does not support multiple inheritance. This means that a class cannot extend more than one class. Therefore, following is illegalpublic class extends Animal, Mammal{}However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritance. The extends keyword is used once, and the parent interfaces are declared in a comma-separated list. For example, if the Hockey interface extended both Sports and Event, it would be declared as −public interface Hockey extends Sports, EventFollowing example demonstrates the running example.Example Live Demointerface Event { public void start(); } interface Sports { ... Read More 
Updated on 23-Jun-2020 15:28:13
Jagged array is a multidimensional array where member arrays are of different size. For example, we can create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating the concept of jagged array.Example Live Demopublic class Tester { public static void main(String[] args){ int[][] twoDimenArray = new int[2][]; //first row has 3 columns twoDimenArray[0] = new int[3]; //second row has 4 columns twoDimenArray[1] = new int[4]; int counter = ... Read More 
Updated on 23-Jun-2020 15:11:42
Iterators are used to traverse through the Java collections. There are three types of iterators.Enumeration − Enumeration is initial iterators introduced in jdk 1.0 and is only for older collections like vector or hashTables. Enumeration can be used for forward navigation only. Element can not be removed using Enumeration.Iterator − Iterator is a universal iterator introduced in Jdk 1.2 and can be used for any collections. Iterator can b e used for forward navigation only. Element can be removed using iterator if remove method is supported.ListIterator − ListIterator is a iterator for List type collections and supports bidirectional navigation.Example Live Demoimport ... Read More 
Updated on 23-Jun-2020 15:12:22
Collections can be iterated easily using two approaches.Using for-Each loop − Use a foreach loop and access the array using object.Using Iterator − Use a foreach loop and access the array using object.DifferencesConcurrentModificationException − Using for-Each loop, if an object is modified, then ConcurrentModificationException can occur. Using iterator, this problem is elliminated.Size Check − Using for-Each, size check is not required. Using iterator if hasNext() is not used properly, NoSuchElementException can occur.Performance − Performance is similar for both cases.Following is an example of using above ways.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Tester { public ... Read More 
Updated on 23-Jun-2020 15:13:29
Often, you will want to cycle through the elements in a collection. For example, you might want to display each element. The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list, and the modification of elements.Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator( ) method that returns an iterator to the start ... Read More 
Updated on 23-Jun-2020 15:14:09
Array can be iterated easily using two approaches.Using for loop - Use a for loop and access the array using index.Using for-each loop - Use a foreach loop and access the array using object.Following is an example of using above ways.Example Live Demopublic class Tester {
public static void main(String[] args) {
int[] array = {1,2,3,4,5};
System.out.println("Array: ");
//Way 1:
for(int i =0; i< array.length; i++){
System.out.println(array[i]);
}
System.out.println("Array: ");
//Way 2:
for (int i : array) {
System.out.println(i);
}
}
}OutputArray:
1
2
3
4
5
Array:
1
2
3
4
5 
Updated on 23-Jun-2020 15:15:04
An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements.Unless the class that implements the interface is abstract, all the methods of the ... Read More Advertisements