All language subtitles for 019 Sorting Objects Alphabetically_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

We can also sort alphabetically.

The goal of this lesson is to sort by class name and price.

Open up the folder for this lesson by following this path inside the resources.

The string class also implements comparable.

It follows that the string class overrides compared to.

The compared to method for string objects returns a negative number if the character in the first string

has a lower Unicode value than the character in the specified object.

Zero, if the strings are identical, which makes sense.

And a positive number, if a character in the first string has a higher Unicode value than a character

in the second string.

We'll test the first case first, we have John and Amy, we'll call Amy compared to.

John.

The letter A. is expected to have a lower Unicode value than the letter J.

So that's going to return a negative number.

Perfect.

Now, I'll compare Amy to Amy.

Returns zero expected.

Now, I'm going to compare John against Jane.

JNJ, same Unicode value, but the letter O comes after a so we can expect a higher Unicode value perfect.

And if we reverse it, we get a negative number.

So based on this information that you just got, go back to the product application.

And what I want you to do is sort the products by alphabetical order based on their class type, then

sort the rest by price.

Here are some hints you can get the class type by using get class and you can get the name of the class

by using get class, get simple name.

I'll give you the chance to pause the video and try this out.

I hope you figured it out.

So what I'm going to do is inside compared to I'll get the name of the current object.

String class name.

Is equal to this doGet class, that simple name.

And I'll get the last name of the specified object.

All right, now we're going to check if the class names aren't equal.

If that's the case, we're going to return the result from comparing the first class name to the second

one.

Here we're comparing two strings, and if the two objects don't happen to share the same class, so,

for example, if this is pants and this is shirt compared to is going to return an integer, that depends

on the letters in each name.

Let's test this out by running the debugger.

These two objects don't share the same class.

This is Pence, this is Schertz, the letter s is expected to have a higher Unicode value than the letter

P.

So this is going to return a positive value, which means shirt is going to come after pence.

Now we're comparing pants and pants, the two pants are part of the same class, however, the price

of the current object is higher than the price of the specified object.

So compared to returns, a positive number.

So it's going to sort the current object that come after the specified one.

And so basically it's going to keep comparing each object against another object.

First, it prioritizes alphabetical order.

And if the two objects share the same class, then it's going to sort of by comparing the price of each

product.

Ultimately, we get an array where objects of different classes are sorted based on the class name,

and every object of the same class are compared by price.

The sort method can easily sort to comparable objects, sort uses compare to to determine how to sort

your objects.

And if the two objects don't have the same class, the one with characters that have a lower Unicode

value are going to be sorted first.

If the names happen to be equal, then the objects are compared based on their price.

As a result, our comparable objects are sorted based on alphabetical order and price.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.