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

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -