Java Vector listIterator() MethodThe listIterator() Java Vector class method returns a list iterator over the elements in the given list in a proper sequence. There is two different types of Java listIterator() method which can be differentiated depending on its parameter. These are:
listIterator() Method:This method is used to get a list iterator over the elements in the given list in a proper sequence. listIterator(int index) Method:This method is used to get a list iterator over the elements in the given list in a proper sequence. The returned list starts at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. SyntaxFollowing is the declaration of listIterator() method: Parameter
ReturnThe listIterator() method returns a list iterator over the elements in this list in a proper sequence. ExceptionsIndexOutOfBoundsException- This method has thrown an exception if the index is out of range i.e. (index < 0 || index > size()). Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Iterate elements are: Two Three Four Five Example 2Test it NowOutput: Iterate elements are: Orange Mango Banana Apple Example 3Test it NowOutput: Iterate elements are: 1 2 3 4 5 Example 4Test it NowOutput: Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 25 at java.base/java.util.Vector.listIterator(Vector.java:1234) at myPackage.VectorListIteratorExample4.main(VectorListIteratorExample4.java:12) Next TopicJava Vector |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India