Skip to content

Latest commit

 

History

History
35 lines (22 loc) · 804 Bytes

28.md

File metadata and controls

35 lines (22 loc) · 804 Bytes

I'm a bit tired of using loops to print an array,

Java has a function called toString, it takes your array as an argument, and it returns a string that we can print.

toString

Updating Arrays

It's time to learn how to update arrays.

String[] flavours = { "Sweet", "Sour", "Bitter" };
flavours[2] = "Salty";

Is it possible to change the array length ?

NO.

Once you create an array, you cannot resize it.

String[] menu = { "Espresso", "Iced Coffee", "Latte" };
String[] newMenu = new String[5];

newMenu

for (int i = 0; i < menu.length; i++) {
    newMenu[i] = menu[i];
}