Feb 05

The Arrays class has a set of helper toString methods for converting an array to a string representation.

String representation = Arrays.toString(array);

This will work for all array types. For Objects it uses the toString() method of the type to convert array elements.

If you need more control how the array is represented then you will need to implement the conversion yourself using a loop.

written by objects \\ tags: , , ,

Oct 08

Use the toString() method of the Arrays utility class.


Object[] array = new Object[] { "abc", "123", "test" };
String s = Arrays.toString(array);
// s is now "[abc, 123, test]"

written by objects \\ tags: , , , ,

Oct 01

Either use the format() method of the SimpleDateFormat class, or the (static) format() method of the String class.


DateFormat dateFormat = new SimpleDateFormat("hhmmddMMyy");
Date today = new Date();
String formatted = dateFormat.format(today);
String formatted2 = 
   String.format("%<tH%<tM%<tS%tY%<tm%<td", today);

written by objects \\ tags: , , ,