Lesson 16 of 34

ArrayList: வளரும் பட்டியல்ArrayList: A List That Grows

9 min 30 XP

Array-ன் அளவு நிலையானது. எத்தனை உறுப்புகள் வரும் என்று தெரியாதபோது ArrayList பயன்படுத்துங்கள், அது தானாக வளரும். int-க்கு பதிலாக Integer, double-க்கு பதிலாக Double எழுத வேண்டும்.

An array has a fixed size. When you don't know how many items you'll have, use an ArrayList, which grows by itself. Write Integer instead of int and Double instead of double inside the < >.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Array: arr.length (bracket இல்லை). String: s.length(). ArrayList: list.size(). Interview-ல் இந்த மூன்றையும் குழப்ப வேண்டாம்!

Array: arr.length (no brackets). String: s.length(). ArrayList: list.size(). Don't mix these three up in an interview!

Challenge

+30 XP

n மற்றும் n எண்களைப் படித்து, இரட்டை (even) எண்களை மட்டும் ஒரு ArrayList-ல் சேர்த்து அதை print செய்யுங்கள். Input: 6 1 4 7 10 12 3 Output: [4, 10, 12]

Read n and n numbers. Put only the even numbers into an ArrayList and print it. Input: 6 1 4 7 10 12 3 Output: [4, 10, 12]

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.