
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

144 Views
To create a new list with values from fields from existing list with Function Mapper, the following is an example. Here, we have a class Employee −class Employee { private String emp_name; private int emp_age; private String emp_zone; }The following is an example that creates a new list from existing with Function Mapper −Example Live Demoimport java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Function; public class Demo { public static void main(String args[]) { List < Employee > emp = Arrays.asList(new Employee("Jack", 29, "South"), new Employee("Tom", 24, "North"), new Employee("Harry", 35, ... Read More

587 Views
In this article, we will learn how to use a LinkedHashSet in Java to add and remove elements while maintaining the insertion order. You will see how elements are stored, removed, and updated in a LinkedHashSet without altering the sequence in which they were added. Problem Statement Write a Java program to add elements to a LinkedHashSet, remove specific elements, and display the updated set while ensuring the insertion order of the elements remains unchanged. Below is a demonstration of the same − Input Set = [20, 60, 80, 120, 150, 200, 220, 260, 380] Output Set = [20, 60, ... Read More

394 Views
Let us create a queue from LinkedList like this −Queuequeue = new LinkedList(); queue.add("P"); queue.add("Q"); queue.add("R"); queue.add("S"); queue.add("T"); queue.add("U"); queue.add("V");Now, use a List to display the elements of the queue −Listlist = new ArrayList(queue);Example Live Demoimport java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; public class Demo { public static void main(String[] args) { Queuequeue = new LinkedList(); queue.add("P"); queue.add("Q"); queue.add("R"); queue.add("S"); queue.add("T"); queue.add("U"); queue.add("V"); Listlist = new ArrayList(queue); for (Object ... Read More

392 Views
In this article, we will learn how to use the Properties class in Java to store and display key-value pairs. The Properties class is useful for handling configuration settings or storing data in a structured way, where both keys and values are strings. By using the put() method, we can easily add values to a property list and later retrieve or display these key-value pairs. This approach provides a simple and efficient way to manage data in a key-value format in Java applications. Problem Statement A properties list contains country-year pairs. Write a Java program to store values ... Read More

1K+ Views
In this article, we will learn how to convert a Properties list into a Map in Java. The Properties class is commonly used to store key-value pairs, but sometimes you may need to work with these pairs in a Map structure. We will demonstrate how to take the properties and convert them into a HashMap. Problem Statement Write a program in Java to convert the properties list into a Map structure − Output Key and Value of the Map... P: 1 Q: 2 R: 3 S: 4 T: 5 U: 6 V: 7 Steps to convert the properties list into ... Read More

155 Views
To get Tail Map from TreeMap, let us first create a TreeMap and set key-value pair −TreeMaptMap = new TreeMap(); tMap.put("1", "A"); tMap.put("2", "B"); tMap.put("3", "C"); tMap.put("4", "D"); tMap.put("5", "E"); tMap.put("6", "F"); tMap.put("7", "G");Now, let’s say you need to get the tailmap from 2 i.e. all the key-value pairs after 2. For that, use the method tailMap() −SortedMapmap = tMap.tailMap("2");Example Live Demoimport java.util.SortedMap; import java.util.TreeMap; public class Demo { public static void main(String[] args) { TreeMaptMap = new TreeMap(); tMap.put("1", "A"); tMap.put("2", "B"); tMap.put("3", "C"); ... Read More

2K+ Views
Two lists are equal if they consist of same number of elements in the same order.Let’s say we have the following two lists −ListarrList1 = Arrays.asList(new Integer[] { 10, 20, 30, 45, 55, 70, 90, 100 }); ListarrList2 = Arrays.asList(new Integer[] {15, 25, 35, 50, 55, 75, 95, 120});Now, let’s find out whether both the lists are equal or not −arrList1.equals(arrList2);If both the above lists have equal elements, then TRUE is returned, else FALSE is the return value.Example Live Demoimport java.util.Arrays; import java.util.List; public class Demo { public static void main(String[] a) { ListarrList1 = Arrays.asList(new Integer[] ... Read More

238 Views
Create a List in Java −List< String >list = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" );Now, let’s say you want to get the frequency of element P. For that, use the Collections.frequency() method −Collections.frequency(list, "P");A shown above, we can find the occurrence of any letter as well −Collections.frequency(list, "T");Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo { public static void main(String[] args) { Listlist = Arrays.asList("P", "Q", "R", "P", "T", "P", "U", "V", "W", "X", "W" ); int checkOccurrence = Collections.frequency(list, "P"); System.out.println("Occurrence ... Read More

1K+ Views
To check capacity in Java, firstly create a list and add elements. After that use ensureCapacity() and increase the capacity.Let us first create an ArrayList and add some elements −ArrayListarrList = new ArrayList(5); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500);Now, increase the capacity of the ArrayList −arrList.ensureCapacity(15);Meanwhile, with the size() method, you can check the current size of the ArrayList as well.Example Live Demoimport java.util.ArrayList; public class Demo { public static void main(String[] a) { ArrayListarrList = new ArrayList(5); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500); ... Read More

3K+ Views
Create a Date object −Date date = new Date();Now, set the ZonedId to default −final ZoneId id = ZoneId.systemDefault();Convert java.util.date to ZonedDateTime −System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));Example Live Demoimport java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Date; public class Demo { public static void main(String[] args) { Date date = new Date(); final ZoneId id = ZoneId.systemDefault(); System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id)); } }Output2019-04-19T00:37:33.344+05:30[Asia/Calcutta]