- 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 9313 Articles for Object Oriented Programming
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
108 Views
The method java.util.ArrayList.removeAll() removes all the the elements from the ArrayList that are available in another collection. This method has a single parameter i.e. the Collection whose elements are to be removed from the ArrayList.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[]) throws Exception { List aList1 = new ArrayList(); aList1.add("Anna"); aList1.add("John"); aList1.add("Mary"); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
660 Views
The sub-list of an ArrayList can be obtained using the java.util.ArrayList.subList() method. This method takes two parameters i.e. the start index for the sub-list(inclusive) and the end index for the sub-list(exclusive) from the required ArrayList. If the start index and the end index are the same, then an empty sub-list is returned.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("Apple"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
2K+ Views
Use the firstEntry() method in TreeMap to retrieve the first entry.Create a TreeMap and add some elementsTreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");Now, retrieve the first entrym.firstEntry()The following is an example to retrieve first entry in the TreeMapExample Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada"); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
65 Views
To get floor key means to return the greatest key less than or equal to the given key, or null if there is no such key. This can be done with the floorKey() metho.The following is an example to get floor key from NavigableMapExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
67 Views
The navigableKeySet() method is used to get view of the Map from NavigableMap.Let us first create a NavigableMapNavigableMap n = new TreeMap();Add some elements in the NavigableMapn.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get Navigable Key Set nown.navigableKeySet()The following is an example to get navigable key setExample Live Demoimport java.util.ArrayList; import java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
26K+ Views
An element can be retrieved from the ArrayList in Java by using the java.util.ArrayList.get() method. This method has a single parameter i.e. the index of the element that is returned.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[]) throws Exception { List aList = new ArrayList(); aList.add("James"); aList.add("George"); aList.add("Bruce"); aList.add("Susan"); ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
189 Views
Elements can be filled in a Java char array in a specified range using the java.util.Arrays.fill() method. This method assigns the required char value in the specified range to the char array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element to be filled(inclusive), the index of the last element to be filled(exclusive) and the value that is to be stored in the array elements.A program that demonstrates this is given as followsExample Live Demoimport java.util.Arrays; public class Demo { public static void main(String[] argv) throws Exception { ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
69 Views
Returning a shallow copy means to copy elements of one IdentityHashMap to another. For this, clone() method is used.The following is an example to return a shallow copy of IdentityHashMapExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { IdentityHashMap m = newIdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450); System.out.println("IdentityHashMap elements"+ m); System.out.println("Size = " + m.size()); System.out.println("Cloned Map = " + m.clone()); 0System.out.println("Size = " + m.size()); } }OutputIdentityHashMap elements {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10 Cloned Map = {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
97 Views
Use the containsValue() method to check whether a particular value exists in IdentityHashMap or not.Create a IdentityHashMapMap m = newIdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);Now, let’s say we need to check whether value 100 exists or not. For that, use the containsValue() method like thism.containsValue(100)The following is an example to check for the existence of a value in IdentityHashMapExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { Map m = newIdentityHashMap(); ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
81 Views
Use the containsKey() method to check whether a particular key exists in IdentityHashMap or not.Create a IdentityHashMapMap m = newIdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);Now, let’s say we need to check whether key 7 exists or not. For that, use the containsKey() method like thism.containsKey(“7”)The following is an example to check for the existence of a key in IdentityHashMapExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { Map m = newIdentityHashMap(); m.put("1", 100); ... Read More