Not understanding what is being passed into method
Question: So I've been given pre-written code and I have to fill in the `comepareTo`
function. It needs to compare strings and sort them by length but I'm not sure
what is being passed in the method.

    
    
     import java.util.Arrays;
    
     public class testString implements Comparable<testString> {
      String tempStr;
    
     public testString(String str) {
        tempStr = str;
     }
    
     public String toString() {
       return tempStr;
     }
    
     public int compareTo(testString Str2) {
    
      return 0;
     }
    
    
     String [] list = {"dog", "cat", "lion", "python", "giraffe", "emu"};
     testString [] list2 = new testString[list.length];
     for (int i=0; i<list2.length; i++) {
       list2[i] = new testString(list[i]);
     }
    

I'm not exactly sure what the type is that is being passed into the
`compareTo` function (Str2).  
I thought it would be a list and I could run through it with a for loop, but
that's giving me errors if I try Str2[1].


Answer: Str2 parameter is an object of type testString (your defined class). The
method is used to compare the current object with the one received as
parameter. To make sense such a comparison the objects must be of the same
type.

check also the API documentation for Comparable interface.
<https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html>

The method compareTo is part of this interface.

In your case, the easiest implementation would be: return
this.tempStr.compareTo(Str2.tempStr);

of course, Str2 must not be null :)

