java - Incompatible int to String (getLast() method) -
i have string array
string[] names;
lets there given number of elements in array
i make getlast method returns string
public string getlast() { return names.length - 1; }
this gives me error it's incompatible.
how return string?
also same add method
public void add(int index, string element){
i'm curious how work without using linkedlist or arraylist, rather array-based list.
get last element:
public string getlast() { return names[names.length - 1]; }
add string element array
public void add(int index, string element) { int len = names.length; if (index < len) names[index] = element; else { names = arrays.copyof(names, len + (index - len + 1)); names[index] = element; } }
Comments
Post a Comment