You can use the List.addAll() method. It accepts a Collection as an argument, and your set is a Collection.
List<String> mainList = new ArrayList<String>(); mainList.addAll(set);
EDIT: as respond to the edit of the question.
It is easy to see that if you want to have a Map
with List
s as values, in order to have k different values, you need to create k different lists.
Thus: You cannot avoid creating these lists at all, the lists will have to be created.
Possible work around:
Declare your Map
as a Map<String,Set>
or Map<String,Collection>
instead, and just insert your set.
Related Posts:
- How to avoid “ConcurrentModificationException” while removing elements from `ArrayList` while iterating it? [duplicate]
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - Convert list to array in Java [duplicate]
- Converting array to list in Java
- stale element reference: element is not attached to the page document
- Python Sets vs Lists
- java, get set methods
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- HashSet vs. ArrayList
- How to initialize List
object in Java? - Is there a concurrent List in Java’s JDK?
- “Instantiating” a List in Java? [duplicate]
- Create a List of primitive int?
- How to print out all the elements of a List in Java?
- Type List vs type ArrayList in Java
- List of Arrays in Java
- How to calculate the intersection of two sets?
- Incompatible types List of List and ArrayList of ArrayList
- Efficient way to do batch INSERTS with JDBC
- How to sort a HashSet?
- Union or intersection of Java Sets
- Get difference between two lists
- How to print out all the elements of a List in Java?
- What’s the difference between HashSet and Set?
- convert string to arraylist
in java - How do I join two lists in Java?
- When to use a Map instead of a List in Java?
- Fastest way to put contents of Set
to a single String with words separated by a whitespace? - How to fix “A JNI error has occurred, please check your installation.”
- Java Runtime Environment not found error when I open an application
- “PKIX path building failed” and “unable to find valid certification path to requested target”
- What exactly does a jar file contain?
- What is the best way to implement constants in Java?
- What is the reason behind “non-static method cannot be referenced from a static context”?
- What does ” || ” mean in Java? [duplicate]
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- “int cannot be dereferenced” in Java
- What is a Key-Value Pair?
- “Missing return statement” within if / for / while
- Understanding regex in Java: split(“\t”) vs split(“\\t”) – when do they both work, and when should they be used
- Make copy of an array
- How can I use ant
to execute commands on linux? - Invalid initial heap size -Xms4096M
- How do I use a PriorityQueue?
- What does Java option -Xmx stand for?
- Global variables in Java
- Constructor cannot be applied to given types?
- Printing HashMap In Java
- Java “.class expected”
- Java Initialize an int array in a constructor
- How Exactly Does @param Work – Java
- Return string Input with parse.string
- Android ListView headers
- What does -XX:MaxPermSize do?
- What does .class mean in Java?
- PrintWriter append method not appending
- Using ADB to capture the screen
- What is the difference between response.sendRedirect() and request.getRequestDispatcher().forward(request,response)
- Recursion vs. Iteration (Fibonacci sequence)
- What is difference between Errors and Exceptions?
- What is the difference between Integer and int in Java?
- Static Error: This class does not have a static void main method accepting String[]
- “uses unchecked or unsafe operations”
- possible lossy conversion from long to int?
- Java substring: ‘string index out of range’
- throw checked Exceptions from mocks with Mockito
- How to sort an array of objects in Java?
- HashSet vs. List performance
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- keytool error Keystore was tampered with, or password was incorrect
- How to override toString() properly in Java?
- Returning null in a method whose signature says return int?
- FXML Load exception
- NullPointerExcetion Native Method Accessor… Hashing Words Issue
- How to convert currentTimeMillis to a date in Java?
- How to clear console in Java – Eclipse
- Java TreeMap Comparator
- What is the use of System.in.read()?
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- JDK was not found on the computer for NetBeans 6.5
- In Java, how to assign the variable number=Integer.parseInt(args[0]) a value if no argument is passed?
- Connection Java – MySQL : Public Key Retrieval is not allowed
- Whitespace Matching Regex – Java
- Size has private access in ArrayList
- Iterator for a linkedlist
- Hide Utility Class Constructor : Utility classes should not have a public or default constructor
- Android – Start service on boot
- JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object
- Sending POST data in Android
- When is “java.io.IOException:Connection reset by peer” thrown?
- Java ArrayList of Doubles
- what is update-alternatives command in linux and what is the use of it?
- java: use StringBuilder to insert at the beginning
- How to extract .war files in java? ZIP vs JAR
- What is the difference between run-time error and compiler error?
- What is the difference between ArrayList.clear() and ArrayList.removeAll()?
- Test if element is present using Selenium WebDriver?
- Increase heap size in Java
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- what does x– or x++ do here?