- 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 4337 Articles for Java 8
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
26K+ Views
The index of a particular element in an ArrayList can be obtained by using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurrence of the element that is specified. If the element is not available in the ArrayList, then this method returns -1.A program that demonstrates this is given as follows.Example Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { List aList = new ArrayList(); aList.add("Orange"); aList.add("Apple"); aList.add("Peach"); aList.add("Guava"); aList.add("Mango"); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
62 Views
The pollFirstEntry() method in NavigableMap remove and return a key-value mapping associated with the least key in this mapThe following is an example to implement pollFirstEntry() methodExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put(5, "Tom"); n.put(9, "John"); n.put(14, "Jamie"); n.put(1, "Tim"); n.put(4, "Jackie"); n.put(15, ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
396 Views
The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList.A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Demo { public static void main(String args[]) throws Exception { List aList = new ArrayList(); aList.add("Sally"); aList.add("George"); aList.add("John"); aList.add("Susan"); aList.add("Martha"); aList = Collections.unmodifiableList(aList); System.out.println("The ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
267 Views
The elements of a Collection can be inserted at the specified index of the ArrayList using the method java.util.ArrayList.addAll(). This method has two parameters i.e. the specific index at which to start inserting the Collection elements in the ArrayList and the Collection itself.If there is an element already present at the index specified by ArrayList.addAll() then that element and all subsequent elements are shifted to the right to make the space for the Collection elements in the ArrayList.A program that demonstrates this is given as follow.Example Live Demoimport java.util.ArrayList; import java.util.Vector; public class Demo { public static void main(String[] args) ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
104 Views
The ceiling() method returns the least element greater than or equal to the given element i.e. 30 hereceiling(30)The following is an example to implement the ceiling method in JavaExample Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo { public static void main(String[] args) { NavigableSet set = new TreeSet(); set.add(10); set.add(25); set.add(40); set.add(55); set.add(70); set.add(85); set.add(100); System.out.println("Returned Value = " + set.ceiling(30)); } }OutputReturned Value = 40
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
97 Views
Use Iterator class to fetch elements of TreeSet.Create a TreeSet and add elements to itTreeSet set = new TreeSet(); set.add("13"); set.add("11"); set.add("12"); set.add("16"); set.add("19"); set.add("23"); set.add("21"); set.add("20"); set.add("30");Now, to display the elements, use Iterator classIterator i = set.iterator(); while(i.hasNext()){ System.out.println(i.next()); }The following is an example that fetch elements of TreeSet using IterationExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet set = new TreeSet(); set.add("13"); set.add("11"); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
144 Views
To get the element ordered last i.e. the last element in TreeSet, use the last() method.Create a TreeSet and add elements to itTreeSet set = new TreeSet (); set.add("65"); set.add("45"); set.add("19"); set.add("27"); set.add("89"); set.add("57");Now, get the last elementset.last()The following is an example to get the element ordered last in TreeStExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet set = new TreeSet (); set.add("65"); set.add("45"); set.add("19"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
687 Views
The elements of the ArrayList can be accessed one by one by using a for loop. A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String[] args) { ArrayList aList = new ArrayList(); aList.add("Sun"); aList.add("Moon"); aList.add("Star"); aList.add("Planet"); aList.add("Comet"); System.out.println("The ArrayList elements are:"); for (String s : aList) { System.out.println(s); } } }OutputThe output of the above ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
6K+ Views
The iterator can be used to iterate through the ArrayList wherein the iterator is the implementation of the Iterator interface. Some of the important methods declared by the Iterator interface are hasNext() and next().The hasNext() method returns true if there are more elements in the ArrayList and otherwise returns false. The next() method returns the next element in the ArrayList.A program that demonstrates iteration through ArrayList using the Iterator interface is given as followsExample Live Demoimport java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Demo { public static void main(String[] args) { List aList = new ArrayList(); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
91 Views
Let us first create a NavigableMapNavigableMap n = new TreeMap();Now, let us add some elementsn.put("A", 888); n.put("B", 999); n.put("C", 444); n.put("D", 555); n.put("E", 666); n.put("F", 888);The following is the complete example to create NavigableMap, add elements and display themExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", 888); n.put("B", 999); n.put("C", 444); ... Read More