- 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
Java Program to find keys from a Linked HashMap and store it in a list
Let us first create a LinkedHashMap with key-value pair −
Map<String, String>map = new LinkedHashMap<String, String>(); map.put("1", "Katie"); map.put("2", "Peter"); map.put("3", "Amy"); map.put("4", "Kane"); map.put("5", "Colin"); map.put("6", "Andre"); map.put("7", "Pollard"); map.put("8", "David"); map.put("9", "Jofra"); map.put("10", "Akila");
Now, create a new List and store the keys in it for the above Map −
List<String>list = new ArrayList<String>(); list.addAll(map.keySet());
Example
import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class Demo { public static void main(String[] args) { Map<String, String>map = new LinkedHashMap<String, String>(); map.put("1", "Katie"); map.put("2", "Peter"); map.put("3", "Amy"); map.put("4", "Kane"); map.put("5", "Colin"); map.put("6", "Andre"); map.put("7", "Pollard"); map.put("8", "David"); map.put("9", "Jofra"); map.put("10", "Akila"); List<String>list = new ArrayList<String>(); list.addAll(map.keySet()); System.out.println("Keys..."); for (String str: list) { System.out.println(str); } } }
Output
Keys... 1 2 3 4 5 6 7 8 9 10
- Related Articles
- Java Program to find keys from both the Linked HashMap and store it in a list alternatively
- Sorting a HashMap according to keys in Java
- Program to find folded list from a given linked list in Python
- Retrieve all the keys from HashMap in Java
- Program to find linked list intersection from two linked list in Python
- Java Program to remove a key from a HashMap
- Java Program to retrieve the set of all keys and values in HashMap
- Java Program to retrieve the set of all keys in HashMap
- Sorting a HashMap according to keys in C#
- Sort HashMap based on keys in Java
- Java program to generate random numbers within a given range and store in a list
- Golang program to access elements from a linked list
- Python program to find the maximum and minimum value node from a doubly linked list
- Python program to find the maximum and minimum value node from a circular linked list
- C program to store the car information using dynamic linked list.

Advertisements