As

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View As as PDF for free.

More details

  • Words: 146
  • Pages: 2
import java.io.*; import java.util.*; class song implements Comparable<song> { String title; String artist; public boolean equals(Object asong) { song s=(song) asong; return getTitle().equals(s.getTitle()); } public int hashCode() { return title.hashCode(); } song(String t,String a) { title=t; artist=a; } public String getTitle() { return title; } public String getArtist() { return artist; } public String toString() { return title+" : "+artist; }

}

public int compareTo(song s) { return title.compareTo(s.getTitle()); }

class Jutebox5 { ArrayList<song> songList=new ArrayList<song>(); public static void main(String g[]) { new Jutebox5().go(); } public void go() { getSong(); System.out.println("Original song list......\n");

}

System.out.println(songList); HashSet<song> s1=new HashSet<song>(); s1.addAll(songList); System.out.println("after sorted by hash......\n"); System.out.println(s1); Collections.sort(songList); System.out.println("song list after sorted......\n"); System.out.println(songList);

public void getSong() { try { File f=new File("SongList.txt"); BufferedReader reader=new BufferedReader(new FileReader(f)); String line=null; while((line=reader.readLine())!=null) { addSongs(line); } } catch(Exception e){} } public void addSongs(String linetoparse) { String[] tokens=linetoparse.split("/"); song s=new song(tokens[0],tokens[1]); songList.add(s); } }

Related Documents

As As
May 2020 47
As
May 2020 41
As
April 2020 17
As
May 2020 11
As
July 2020 6
As
December 2019 38