- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Convert Set of String to Array of String in Java
At first, create a Set of string −
Set<String> setStr = new HashSet<>(Arrays.asList("osCommerce", "PrestaShop", "Magento","Wordpres", "Drupal"));
Now, use the toArray() method to convert to array of string −
String[] arrStr = setStr.toArray(new String[0]);
Example
Following is the program to convert Set of String to Array of String in Java −
import java.util.Arrays; import java.util.Set; import java.util.HashSet; public class Demo { public static void main(String[] args) { Set<String> setStr = new HashSet<>( Arrays.asList("osCommerce", "PrestaShop", "Magento","Wordpres", "Drupal")); System.out.println("Set of String: " + setStr); String[] arrStr = setStr.toArray(new String[0]); System.out.println("Array of String = "+ Arrays.toString(arrStr)); } }
Output
Set of String: [Wordpres, Drupal, PrestaShop, osCommerce, Magento] Array of String = [Wordpres, Drupal, PrestaShop, osCommerce, Magento]
- Related Articles
- Program to convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Convert an ArrayList of String to a String array in Java
- Convert a Set of String to a comma separated String in Java
- How to convert string to array of integers in java?
- Convert string to char array in Java
- Convert Char array to String in Java
- how to convert Object array to String array in java
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- How to convert an array to string in java?
- how to convert vector to string array in java
- Java Program to convert byte[] array to String
- Java Program to convert String to byte array
- Java Program to convert Char array to String

Advertisements