- 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 create a string from a Java ArrayList?
To convert the contents of an ArrayList to a String, create a StringBuffer object append the contents of the ArrayList to it, finally convert the StringBuffer object to String using the toString() method.
Example
import java.util.ArrayList; public class String_ArrayList { public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("Hello"); al.add("are"); al.add("you"); StringBuffer sb = new StringBuffer(); for (String s : al) { sb.append(s); sb.append(" "); } String str = sb.toString(); System.out.println(str); } }
Output
Hello are you
- Related Articles
- How to create a string from a Java Array?
- Create a new ArrayList from another collection in Java
- How to create an ArrayList from an Array in Java?
- How to search for a string in an ArrayList in java?
- Java Program to create a boolean variable from string
- How to remove a SubList from an ArrayList in Java?
- Convert an ArrayList of String to a String array in Java
- Java Program to create a BigDecimal from a string type value
- How to convert a comma separated String into an ArrayList in Java?
- Java Program to Create String from Contents of a File
- Java Program to create Stream from a String/Byte Array
- Converting ArrayList to String[] in java
- How do I create a Java string from the contents of a file?
- How to create a hash from a string in JavaScript?
- How to create a function from a string in JavaScript?

Advertisements