— Scott McNealy, Sun Microsystems Chairman, President and ceo


chapter 16 import java.util.*; import java.io.*; public class Jukebox3 { ArrayList songList = new ArrayList()



Download 40,57 Mb.
Pdf ko'rish
bet504/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   500   501   502   503   504   505   506   507   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

chapter 16
import java.util.*;
import java.io.*;
public class Jukebox3 {
ArrayList songList = new ArrayList();
public static void main(String[] args) {
new Jukebox3().go();

public void
go()
{
getSongs(); 
System.out.println(songList);
Collections.sort(songList);
System.out.println(songList);

void 
getSongs()
{
try {
File file = new File(“SongList.txt”);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
while ((line= reader.readLine()) != null) {
addSong(line);
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
void 
addSong(String lineToParse)
{
String[] tokens = lineToParse.split(“/”);
 
 
Song nextSong = new Song(tokens[0], tokens[1], tokens[2], tokens[3]);
 
 
songList.add(nextSong);

}
This still doesn’t 
explain why the sort method 
failed on an ArrayList of Songs 
but worked for an ArrayList of 
Strings...
Remember where we were...
This is where it breaks! It worked fine when 
passed in an ArrayList, but as soon as we 
tried to sort an ArrayList, it failed.
File Edit Window Help Bummer
%javac Jukebox3.java
Jukebox3.java:15: cannot find symbol
symbol : method sort(java.util.ArrayList)
location: class java.util.Collections
Collections.sort(songList);
^
1 error
sorting 
a Song


collections 
with 
generics
you are here
4
547
public static

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   500   501   502   503   504   505   506   507   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish