- By Using StringUtils.join method in apache common we can easily convert String[] to String.
- You can download this jar from Here.
- package commonsUtils;
- import org.apache.commons.lang.StringUtils;
- public class SampleRunnable {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String[] stringArray = { "one", "two", "three", "four", "five" };
- String finalString = StringUtils.join(stringArray,","); //Output comma(,) seperated string
- String finalString2 = StringUtils.join(stringArray,":"); //Output colon(,) seperated string
- System.out.println(" finalString :: "+finalString);
- System.out.println(" finalString2 :: "+finalString2);
- }
- }
Output :
finalString :: one,two,three,four,five
finalString2 :: one:two:three:four:five
No comments:
Post a Comment