- Converting array to string and string should not contain any brackets.
- We can convert array to string by iterating array and capturing each element from an array and append to StringBuilder/StringBuffer so that final output will be string without brackets.
- Lets see an example java program to convert array to string by removing brackets.
- So that we can remove brackets from string.
#1 : Java Example program to convert array to string without brackets.
- package com.instanceofjava;
- /**
- * @author www.Instanceofjava.com
- * @category interview programming questions
- *
- * Description: convert array to string without brackets.
- *
- */
- public class ArrayToString {
- public static void main(String[] args) {
- String array[]= {"java","string","without","brackets"};
- StringBuffer strbuffer = new StringBuffer();
- for (String str : array) {
- strbuffer.append(str).append(" ");
- }
- String result = strbuffer.toString();
- System.out.println(result);
- }
- }
Output:
- java string without brackets
No comments