- 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
How to convert a list collection into a dictionary in Java?
Following is an example to convert a list collection into a dictionary in Java.
Example
import java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; public class CollectionDictionary { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); System.out.println(list); Dictionary dictionary = new Hashtable(); Hashtable<Integer, String> hashTable = new Hashtable<Integer, String>(); hashTable.put(1, list.get(0)); hashTable.put(2, list.get(1)); hashTable.put(3, list.get(2)); hashTable.put(4, list.get(3)); System.out.println(hashTable); } }
Output
[JavaFx, Java, WebGL, OpenCV] {4=OpenCV, 3=WebGL, 2=Java, 1=JavaFx}
- Related Articles
- Python program to convert a list of tuples into Dictionary
- How to convert dictionary into list of JavaScript objects?
- How do you convert a list collection into an array in C#?
- How to convert a DataFrame into a dictionary in Pandas?
- How to convert Python Dictionary to a list?
- Convert a Set into a List in Java
- Java Program to Convert Collection into Array
- Java Program to Convert Array into Collection
- Python - Convert a set into dictionary
- Java Program to convert Properties list into a Map
- How to convert list to dictionary in Python?
- How to convert a list into a tuple in Python?
- How I can convert a Python Tuple into Dictionary?
- Convert two lists into a dictionary in Python
- Java program to convert a list of characters into a string

Advertisements