Preview

Ghghghj

Powerful Essays
Open Document
Open Document
1445 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Ghghghj
LECTURE NO.10

Collection - ArrayList
Disadvantage of chronic Array or Array class:
1. Memory Wastage
2. Memory Shortage * If you do not know in advance how many objects an array will hold, you run the risk of declaring either too small an array (and running out of room) or too large an array (and wasting memory).

3. Array is collection of elements which is similar type * Your program might be asking the user for input, or gathering input from a web site. As it finds objects (strings, books, values, etc.) you will add them to the array

4. The size of array is always constant.
5. Size of array must be defined or specified at the time of declaration or instantiation.
6. Array is not flexible for retrieving and adding elements in the array.

Definition: * The ArrayList class is an array whose size is dynamically increased as required.
Data Type: * Reference type.
Storage Location * On Heap
Namespace
* ArrayList class is defined in System.Collection namespace. * While using ArrayList class you must import System.Collection namespace.
i.e. using System.Collection

Difference between Array & ArrayList class * Namespace:-
Array:-System.
ArrayList:-System.Collection. * Size of length
Array:-Length
ArratList:-Count * Methods
Array:-static & property
ArrayList:-public, static & property.
Collection
* Collection is grouping of classes that store elements of type Object and generic collection classes.

When to use ArrayList class * If the number of elements is dynamic, you should use a collection class.

Syntax * ArrayList brm =new ArrayList( );
ArrayList: - class (keyword) brm: - object (identifier) new: - for memory allocation (keyword)
Adding elements in the ArrayList (Add () method) * By using Add () method we can add elements in the ArrayList. * ArrayList method Add appends a new element at the end of an ArrayList. * Add () is a public method accesed by

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Exercise 1: Review of array-based lists Create a project using the classes in the DocSharing area labeled “User-defined array list." Compile it, run it, and review the code that is given carefully. This code tests the ArrayList class provided in the lecture.…

    • 714 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    The purpose of this Lab. is to familiarize student how to solve practical problems programmatically; they will practice on elementary programming using primitive data types, variables, constants, operators, expressions, and input and output. Also, they will learn how to diagnose errors that may occur when a program is compiled or executed. There are some exercises, through which they will understand the concept learn in this chapter.…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Comp 220

    • 1463 Words
    • 6 Pages

    Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.…

    • 1463 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    9. A three-dimensional array can be thought of as ______ of two-dimensional arrays. (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    cis121 chapter 2 and 3

    • 993 Words
    • 6 Pages

    A ____ read is an added statement that gets the first input value in a program.…

    • 993 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Assignment 2

    • 338 Words
    • 2 Pages

    You are not allowed to use ArrayLists or Vectors, only primitive arrays or string arrays if you want.…

    • 338 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    ghghgh

    • 341 Words
    • 2 Pages

    The procedures are: what to do when the fire alarm goes off, letting seniors know when I am not coming into work and reporting an accident at work.…

    • 341 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Data Structure

    • 328 Words
    • 2 Pages

    How do you create an instruction that steps through an array, performing an operation on each item?…

    • 328 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Coding: Questions

    • 2042 Words
    • 18 Pages

    In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.…

    • 2042 Words
    • 18 Pages
    Good Essays
  • Good Essays

    Parallel Arrays

    • 427 Words
    • 2 Pages

    Compared to arrays, linked data structures allow more flexibility in organizing the data and in allocating space for it. With arrays, we must choose a size for our array once and for all; this can be a potential waste of memory. A linked…

    • 427 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    mr angola

    • 329 Words
    • 2 Pages

    Write a Java program to perform basic arithmetic operations which are multiplication and division of two numbers. Numbers are assumed to be integers and will be entered by the user…

    • 329 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    The challenge here is finding all the places that use the array and changing them over to using the ArrayList. For example, in whichITSystem() we have “return systems[idNumber]”, but now we want “return findSystem(idNumber)”. These changes will…

    • 1222 Words
    • 5 Pages
    Powerful Essays
  • Good Essays

    1.2 Write a Java program to display default value of all primitive data types of…

    • 2916 Words
    • 12 Pages
    Good Essays