
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create String from 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
Advertisements