Is there any function in java like toString () to print a String array?
This is a stupid question, but I want to know if there is another way than writing a for loop.
Thank.
String[] array = { "a", "b", "c" }; System.out.println(Arrays.toString(array));
With Apache Commons Lang ,
System.out.println(StringUtils.join(anArray,","));
There is an Arrays.toString() method that converts an array to a string representation of its contents. You can then pass this line to System.out.println or whatever you use to print it. A.
Arrays.toString()
System.out.println
If you need a little more control over the string representation, Google Collections Joiner is there to help!
String[] myArray = new String[] {"a", "b", "c"}; String joined = Joiner.on(" + ").join(myArray); // => "a + b + c"
I think you are looking
System.out.printf(String fmtString, Object ... args)
If you specify the output format using some custom java markup (this is the only part you need to learn). The second parameter is an object, in your case, an array of strings.
Additional Information: Using the Java Printf Method
With op4j ,
String[] myArray = new String[] {"a", "b", "c"}; System.out.println(Op.on(myArray).toList().get());
String[] values= { ... } System.out.println(Arrays.asList(values));