- 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
Copy all elements in Java TreeSet to an Object Array
Create a TreeSet and add elements −
TreeSet<String> tSet = new TreeSet<String>(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet");
Now, let us copy it to object array −
Object[] arr = tSet.toArray(); for (Object ob: arr) { System.out.println(ob); }
The following is an example to copy all elements in TreeSet to an Object Array −
Example
import java.util.*; public class Demo { public static void main(String args[]){ TreeSet<String> tSet = new TreeSet<String>(); tSet.add("TV"); tSet.add("Radio"); tSet.add("Internet"); System.out.println("TreeSet elements = "+tSet); Object[] arr = tSet.toArray(); for (Object ob: arr) { System.out.println(ob); } } }
Output
TreeSet elements = [Internet, Radio, TV] Internet Radio TV
- Related Articles
- Copy all elements of Java HashSet to an Object Array
- Copy all elements of Java LinkedHashSet to an Object Array
- Copy all elements of ArrayList to an Object Array in Java
- Remove all elements from TreeSet in Java
- Python program to copy all elements of one array into another array
- Delete All Odd Elements from an Array in Java
- Swift Program to Copy All the Elements of One Array to Another Array
- C++ Program to Copy All the Elements of One Array to Another Array
- Golang Program To Copy All The Elements Of One Array To Another Array
- Copy all the elements from one set to another in Java
- Create an object array from elements of LinkedList in Java
- Iterate through elements of TreeSet in Java
- Traverse TreeSet elements in descending order in java
- Copy and return all the elements of a masked array in Numpy
- Fetch elements of Java TreeSet using Iteration

Advertisements