title: Iterate Through Custom LinkedList Class of Objects
body: <p>I have created my own <code>LinkedList</code> class and created a <code>LinkedList</code> that will contain object Song (contains title, artist, album, length). The error I am having is that when trying to iterate through the list I am getting the "Can only iterate over array of java.lang.Iterable." I think my issue is that I am iterating over the class instance and therefore am missing something in my linked list class to be able to do this type of iteration. Not to sure what I need to add though, thanks in advance.</p>
  
  <p><strong>Here is where I try to iterate:</strong></p>
  
  <pre><code>System.out.print("Enter song title: ");
  String searchTitle = input.nextLine();
  for ( Song i : list ){
      if ( i.getTitle() == searchTitle ){
          System.out.println(i);
          found = true;
      }
  }
  if ( found != true ){
      System.out.println("Song does not exist.");
  }
  </code></pre>
  
  <p><strong>My LinkedList Class</strong></p>
  
  <pre><code>public class LinkedList {
  
  private Node first;
  
  private Node last;
  
  public LinkedList(){
      first = null;
      last = null;
  }
  
  public boolean isEmpty(){
      return first == null;
  }
  
  public int size(){
      int count = 0;
      Node p = first;
      while( p != null ){
          count++;
          p = p.getNext();
      }
      return count;
  }
  
  public Node get( int i ){
      Node prev = first;
      for(int j=1; j&lt;=i; j++){
          prev = prev.getNext();
  }
      return prev;
  }
  
  public String toString(){
      String str = "";
      Node n = first;
      while( n != null ){
          str = str + n.getValue() + " ";
           n = n.getNext();
      }
      return str;
  }
  
  public void add( Song c ){
      if( isEmpty() ) {
          first = new Node(c);
          last = first;
      }else{
          Node n = new Node(c);
          last.setNext(n);
          last = n;
      }
  }
  </code></pre>
  
  <p><strong>Song Class</strong></p>
  
  <pre><code>public class Song {
  
      private String title;
  
      private String artist;
  
      private String album;
  
      private String length;
  
      private static int songCounter = 0;
  
      public Song(String title, String artist, String album, String length){
          this.title = title;
          this.artist = artist;
          this.album = album;
          this.length = length;
          songCounter++;
      }
  
      public String getTitle(){
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  
      public String getArtist(){
          return artist;
      }
  
      public void setArtist(String artist) {
          this.artist = artist;
      }
  
      public String getAlbum(){
          return album;
      }
  
      public void setAlbum(String album){
          this.album = album;
      }
  
      public String getLength(){
          return length;
      }
  
      public void setLength(String length){
          this.length = length;
      }
  
      public static int getSongCounter(){
          return songCounter;
      }
  
      public int compareArtist(Song o){
          return artist.compareTo(o.artist);
      }
  
      public int compareTitle(Song o){
          return title.compareTo(o.title);
      }
      @Override
      public String toString(){
          return title +","+artist+","+album+","+length;
      }
  </code></pre>