- 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
Get Size of Java LinkedHashSet
To get the size of LinkedHashSet, use the size() method.
First, set the LinkedHashSet and add elements −
LinkedHashSet<Integer> set = new LinkedHashSet<Integer>(); set.add(10); set.add(20); set.add(30); set.add(40); set.add(50); set.add(60);
Display the size of the LinkedHashSet created above −
set.size()
The following is an example to get the size of LinkedHashSet −
Example
import java.util.*; public class Demo { public static void main(String[] args) { LinkedHashSet<Integer> set = new LinkedHashSet<Integer>(); set.add(10); set.add(20); set.add(30); set.add(40); set.add(50); set.add(60); System.out.println("LinkedHashSet elements..."); System.out.println(set); System.out.println("Size: "+set.size()); } }
Output
LinkedHashSet elements... [10, 20, 30, 40, 50, 60] Size: 6
Advertisements