SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
ARRAY
TA LESSON @ 108-1 JAVA
OUTLINE
‣ Java’s array
‣ ArrayList vs. Array
‣ Demo
‣ Hw2 (Lab)
JAVA’S ARRAY
JAVA’S ARRAY
ARRAY
▸ 陣列列最常⽤用來來儲存資料
▸ 常⾒見見的型態有⼀一維陣列列、⼆二維陣列列
▸ Java宣告陣列列的⽅方式為
▸ int[] array1 = new int[10];
▸ double[][] array2 = new double[10][3];
JAVA’S ARRAY
ARRAY REFERENCE
▸ Java中的陣列列宣告 -> int[] array1 為⼀一個 object
▸ 所以 array2 = array1 會讓 array2 指向 array1 所在的位置
▸ 正確的複製⽅方法為
▸ array2 = Array.copyOf(array1, array1.length());
▸ for(int i=0;i<array1.length();i++)
▸ array2[i] = array1[i];
ARRAYLIST VS. ARRAY
ARRAYLIST VS. ARRAY
ARRAYLIST
▸ ArrayList 是 Java.util 裡內含的package
▸ ArrayList的優點在於彈性佳、可以⾃自由控制陣列列⼤大⼩小、增減
▸ 相比Array我們必須在宣告陣列列時就宣告好⼤大⼩小,ArrayList可
以做到⾃自由增減陣列列內容,⼗十分具有彈性
▸ 因此在進⾏行行未知數⽬目的陣列列操作時,我們可以選⽤用ArrayList
ARRAYLIST VS. ARRAY
ARRAYLIST METHOD
▸ ArrayList<int> arraylist = new ArrayList<int>();
▸ arraylist.add()
▸ 增加⼀一個物品⾄至arraylist裡
▸ arraylist.remove()
▸ 從arraylist裡移除⼀一個物品
▸ arraylist.set(), arraylist.get(), etc.
DEMO
HW2(LAB)
HW2(LAB)
HW2
不理解寫這個的⽤意︖
我們來看個例⼦就知道了
HW2(LAB)
以開源的楓之⾕私服為例
HW2(LAB)
LAB(有時間的話)
1. 請完成⼀一個Monster Class內含String name, int hp
2. 寫⼀一個constructor來來初始化怪物
3. 寫⼀一個getter來來讓main function正常取得怪物資訊
4. 寫⼀一個setter來來讓main function正常設定怪物資訊
5. ⾃自⼰己寫⼀一個Main Class內含main function來來執⾏行行Monster
Q&A

Más contenido relacionado

Más de Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan.

Más de Redhung @ Nationtal Chung Cheng University, Chiayi, Taiwan. (15)

Firmadyne
FirmadyneFirmadyne
Firmadyne
 
Fintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJSFintech Newebpay API using Flask and VueJS
Fintech Newebpay API using Flask and VueJS
 
TA-java-method-109
TA-java-method-109TA-java-method-109
TA-java-method-109
 
TA Lesson Web-109
TA Lesson Web-109TA Lesson Web-109
TA Lesson Web-109
 
TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)TA Lesson Binary Exploitation (Pwn)
TA Lesson Binary Exploitation (Pwn)
 
Reverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & IntroductionReverse Engineering - Assembly & Introduction
Reverse Engineering - Assembly & Introduction
 
TA Lesson3 - Method
TA Lesson3 - MethodTA Lesson3 - Method
TA Lesson3 - Method
 
Web Introduction
Web IntroductionWeb Introduction
Web Introduction
 
Java - TA課 - Let's Begin
Java - TA課 - Let's BeginJava - TA課 - Let's Begin
Java - TA課 - Let's Begin
 
Java - TA課 - 開發環境
Java - TA課 - 開發環境Java - TA課 - 開發環境
Java - TA課 - 開發環境
 
IoT Penetration Talk
IoT Penetration TalkIoT Penetration Talk
IoT Penetration Talk
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
 
Assembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOHAssembly Language Redhung ( x86 ) @ TDOH
Assembly Language Redhung ( x86 ) @ TDOH
 
TP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attackTP-Link SR20 Zero-day attack
TP-Link SR20 Zero-day attack
 
滲透測試入門 Penetration test - white hat hacking introduction
 滲透測試入門 Penetration test - white hat hacking introduction 滲透測試入門 Penetration test - white hat hacking introduction
滲透測試入門 Penetration test - white hat hacking introduction
 

Java - TA課 - Array