All language subtitles for 006 Updating Arrays_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

It's time to learn how to a bitter race.

So far, we use the for loop to run through the length of an array and now you know how to create arrays

as well as how to access their values.

The last step is to learn how to update them.

So inside your Section six folder, create a new file named updating, Erase Java and inside the class,

make sure there's a main method.

Just like we can access array values from their index, we can update them all the same.

So you have an array of three elements, if you want to change an element, just to refer to its index

and then change the value.

It's that simple.

And so I prepared a fine example for us to learn about how to update race, you decided to pursue your

lifelong dream, opened up a cafe, the Java Cafe, your menu starts off pretty simple.

It offers three beverages, the espresso, iced coffee and macchiato.

So inside the class, we're going to store the menu in one array string menu.

Is going to equal an array of three string values.

Espresso.

Iced coffee and macchiato.

Now, I don't know about you, but I'm a bit tired of using loops to print theory.

Java has a function called to string.

It takes your array as an argument and it returns a string that we can print.

So first to write the word erase, wait a bit and click on the first option and what that's going to

do is auto import the utility class.

And so from the erased utility class, we can use the two string method.

The two string method is going to take your array as an argument and return a string copy, we can store

the string copy in a string variable.

And this is really convenient because we can now print the contents of menu as one long string.

Or on the code and nice to string returns a string copy of the array, which you can easily print.

Now, instead of storing the return value, then printing it, I'd rather just print the return value

in one line.

And your coffee is all set up and people are going nuts, but nobody's buying the macchiato, so you

decide to sell lattes instead.

So we're going to do is we're going to update the value at index two and set it equal to latte.

All right, Perfect's.

Now, let's say you want to add more items to the menu, is it possible to change the array length?

And the answer is a big fat no, you cannot change the length of an array.

And that's really unfortunate because your Java cafe is becoming really popular and you need to expand

your menu to accommodate new customers.

There is a lot of demand for house blend and dark roast, but the problem is once you create an array,

you cannot resize it.

The current array only has a room for three items.

So what I can do is create a new array that can store five string values.

So inside the code, I'm going to create a new array that can hold five menu items, string menu.

Is equal to new string that can hold five elements.

The new area has five elements with indexes of zero to four, and by default, the values are null.

Now we're going to create a loop that runs through every item in the old menu, so 4:00 a.m. is equal

to zero.

Remember, indexing an array always starts at zero.

Just at the last index in the array is always one less than the array's length.

And during each run, we're going to print the index I.

As well as the value that we're indexing in the menu.

All right, we're off to a good start.

It runs through the length of the older ray and it prints every element.

Now we need to copy each element from the old array into the new array.

So I'm going to delete this code.

And I'm going to set every element a new menu.

Equal to the element in menu with the same index.

And so from a visual standpoint, this loop runs three times in copies, every value from menu to the

same index as new menu.

To prove this, I'm going to print the contents of new menu as a string.

And as you can see, the first three volumes are copies from the old array, because there was only

three values, the copy from the old array.

But we still have to add house blend and our coast our menu.

So what we'll do is we'll update the element in the next three set that equal to house blend.

And we'll update the elemental index for and set that equal to dark roast.

Rewriting, running the code.

And the Java Cafe is back in business, we successfully updated the menu and we're ready to accommodate

more customers.

From a visual standpoint, you updated the elements and indexes three and four.

Now, your menu is complete and your customers are happy.

In this lesson, you learn how to a bitter race.

You opened up your first cafe, the menu only had three items, your cafe became very popular, so you

decided to add house blend and darkness to your menu.

The problem was you cannot resize an array once you created.

You copied the three elements from menu and to new menu.

And then you manually updated indexes three and four with houseplant and Dark Roast.

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