StringArray to String in java


  • By Using StringUtils.join method in apache common we can easily convert String[] to String.
  • You can download this jar from Here.


  1. package commonsUtils;
  2. import org.apache.commons.lang.StringUtils;

  3. public class SampleRunnable {
  4. public static void main(String[] args) {
  5. // TODO Auto-generated method stub
  6. String[] stringArray = { "one", "two", "three", "four", "five" };
  7. String finalString = StringUtils.join(stringArray,","); //Output comma(,) seperated string
  8. String finalString2 = StringUtils.join(stringArray,":"); //Output colon(,) seperated string
  9. System.out.println(" finalString :: "+finalString);
  10. System.out.println(" finalString2 :: "+finalString2);
  11. }
  12. }
 Output :


 finalString :: one,two,three,four,five
 finalString2 :: one:two:three:four:five



No comments:

Post a Comment