I have written a custom method to use StringBuilder in java. My Requirement is to create a method which accepts any number of arguments of any type and return String by concatenating the arguments.eg. msgBuilder(Hello ,0, how, are, you ,2.5) return Hello 0 how are you 2.5Here is my java code. Please Someone review my code and suggest If I did anything is wrong or Can I use this further in my projects.        public class Test {            public static void main(String[] args ){                String msg = msgBuilder(Hello ,5, How ,are ,you);                System.out.println(msg);            }            private static String msgBuilder(Object... params){                StringBuilder sb = new StringBuilder();                for(Object obj:params){                    sb.append(obj);                }                return sb.toString();            }        }
Method for String Building in java
java;strings
I had this in mind:private static String msgBuilder(Object... params) {    StringBuilder sb = new StringBuilder();    if (params.length > 0) {        sb.append(params[0]);    }    for (int i = 1; i < params.length; ++i) {        sb.append( ).append(params[i]);    }    return sb.toString();}The above version allows you not to hardcode the white space delimiting your tokens. Instead of saying String msg = msgBuilder(Hello , 5,  How , are , you);you can say succintlyString msg = msgBuilder(Hello, 5, How, are, you);Hope that helps.