Java Lab Assignment
Write a method called convertToArray. The method will take a String as an argument and it will return an array of chars. Each index of the String will be stored in each index of the array.
method must be well documented using JavaDoc, example:
/** * The find method checks if the target in the array
* @param String [] a - array of Strings
* @param String t - value to be searched for
* @return true if the String t is found, false otherwise
*/
char[] convertToArray(String s){ if(s==null || s.length()==0){ return null; } else { char[] arr = new char[s.length()]; for(int i = 0;i<s.length();i++){ arr[i] = s.charAt(i); } return arr; } }
//////////////////////////////////////////////
Note: if you want the static method then change the first line of above code to
static char[] convertToArray(String s){
Get Answers For Free
Most questions answered within 1 hours.