Lists and Arrays

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:12 PM on 8/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

48 Terms

1
New cards

What is the purpose of the new operator?

It creates an object and associates it with a variable.

2
New cards

What is the general syntax for declaring a variable that will refer to an object?

ClassName classVar;

3
New cards

What is the syntax for creating an object after declaring its variable?

classVar = new ClassName();

4
New cards

Can declaration and object creation be combined?

Yes, ClassName classVar = new ClassName();

5
New cards

What does Student JS = new Student(); do?

It declares JS as a Student variable and creates a new Student object associated with it.

6
New cards

What is an instance variable?

A variable declared inside a class but outside the constructor and methods.

7
New cards

When are instance variables created?

When an object is instantiated.

8
New cards

Which methods can access an instance variable?

All methods in the class.

9
New cards

How do you refer to an instance variable belonging to a particular object?

objectName.variableName

10
New cards

What does JS.studentName mean?

It refers to the studentName instance variable belonging to the object JS.

11
New cards

What is an ArrayList?

A type of Java list.

12
New cards

What must be specified when declaring an ArrayList?

The type of elements it will contain.

13
New cards

Can an ArrayList contain elements of multiple types?

No, an ArrayList can only contain elements of one specified type.

14
New cards

What do the angle brackets in ArrayList<String> specify?

The type of elements stored in the list.

15
New cards

How do you create an empty ArrayList of Strings?

ArrayList<String> strList = new ArrayList<String>();

16
New cards

Does Java ArrayList support Python's w[i] notation?

No, named methods are used instead.

17
New cards

What does get(i) do?

It returns the item at index i.

18
New cards

What does set(i, value) do?

Sets the item at index i to the specified value.

19
New cards

What does add(value) do?

It adds an item to the list.

20
New cards

What does size() do?

Returns the number of items in the list.

21
New cards

What does indexOf(x) return?

The index of the first occurrence of x, or -1 if it isn’t found.

22
New cards

What does addAll(w2) do?

Adds all elements of w2 to the list.

23
New cards

What does contains(x) do?

Test whether the list contains x.

24
New cards

What does isEmpty() do?

Test whether the list is empty.

25
New cards

What does clear() do?

Removes all items from the list.

26
New cards

What does remove(i) do?

Removes and returns the item at index i.

27
New cards

What does subList(2,4) do?

Produces a sub-list corresponding to the specified range.

28
New cards

What does Collections.sort(w) do?

Sorts the list according to natural ordering.

29
New cards

What is a wrapper type?

An object type corresponding to a primitive type.

30
New cards

What is boxing?

Converting a primitive value into an object.

31
New cards

What is unboxing?

Converting an object back into a primitive value.

32
New cards

What is autoboxing?

Automatic conversion between primitive types and their corresponding object/wrapper types.

33
New cards

Is ArrayList<int> legal?

No.

34
New cards

What should be used instead of ArrayList<int>

ArrayList<Integer>

35
New cards

Why can't ArrayList<int> be used?

ArrayList requires an object type rather than a primitive type.

36
New cards

What happens when nums.add(7) is called on an ArrayList<Integer>?

The primitive int value 7 is automatically converted to an Integer object through autoboxing.

37
New cards

What is a major difference between a Java array and an ArrayList?

A Java array has a fixed number of elements while an ArrayList can change size.

38
New cards

When is the size of a Java array fixed?

When the array is created.

39
New cards

Can the number of elements in an existing Java array be changed?

No.

40
New cards

How is an array of type T represented in Java?

T[]

41
New cards

What does String[] mean?

An array of Strings.

42
New cards

How can an array be initialized in its declaration?

Using curly braces.

43
New cards

Give an example of an initialized String array.

String[] fruit = {“apple“, “pear“, “plum“};

44
New cards

How do you access an element of an array?

Using indexing, e.g. fruit[1]

45
New cards

How do you obtain the length of a Java array?

Using the length field.

46
New cards

Is length for arrays a method or a field?

A field.

47
New cards

What is the syntax for creating an array with a specified size?

new elementType[arraySizeExpression]

48
New cards

What does new String[n] create?

A String array containing n positions initially containing null references.