Similarly, you can declare arrays of other types:
byte[] anArrayOfBytes; short[] anArrayOfShorts; long[] anArrayOfLongs; float[] anArrayOfFloats; double[] anArrayOfDoubles; boolean[] anArrayOfBooleans; char[] anArrayOfChars; String[] anArrayOfStrings;You can also place the square brackets after the array's name:
// this form is discouraged float anArrayOfFloats[];However, convention discourages this form; the brackets identify the array type and should appear with the type designation. Below is an example of converting a date string into Integer Array.
string date_str = "2012/11/06"; String str_arr[] = date_str.split("/"); int[] int_arr = new int[4]; int_arr[0] = Integer.valueOf(str_arr[0]); System.out.println(int_arr[0]);
No comments:
Post a Comment