Topic 4: Arrays & Strings

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

Q: What is an array in Java?

An array is a container object that holds a fixed number of values of a single type.

2
New cards

Q: How do you declare an array in Java?

You declare an array using syntax: type[] arrayName = new type[size]; Example: int[] arr = new int[5];

3
New cards

Q: How do you initialize an array in Java?

You initialize an array by assigning values to its elements. Example: int[] arr = {1, 2, 3, 4, 5};

4
New cards

Q: What is the length of an array in Java?

The length of an array is the number of elements it can hold. It can be accessed using arrayName.length.

5
New cards

Q: How do you access an array element?

You access an array element using its index. Example: arr[0] accesses the first element.

6
New cards

Q: What is a multidimensional array in Java?

A multidimensional array is an array of arrays. Example: int[][] matrix = new int[3][3];

7
New cards

Q: What is a String in Java?

A String is a sequence of characters, used to store text. In Java, Strings are objects, not primitive types.

8
New cards

Q: How do you declare a String in Java?

You declare a String by using the String keyword. Example: String str = "Hello";

9
New cards

Q: What is the difference between String, StringBuilder, and StringBuffer?

String is immutable, meaning its value cannot be changed. StringBuilder and StringBuffer are mutable, and StringBuffer is thread-safe.

10
New cards

Q: How do you concatenate two strings in Java?

You can concatenate strings using the + operator or the concat() method. Example: "Hello" + " World" results in "Hello World".

11
New cards

Q: How do you compare strings in Java?

You compare strings using the .equals() method for content equality or == for reference equality.

12
New cards

Q: What is the length of a string in Java?

The length of a string can be accessed using the .length() method. Example: str.length() gives the number of characters in the string.

13
New cards

Q: How do you convert a string to uppercase in Java?

You can convert a string to uppercase using the .toUpperCase() method. Example: str.toUpperCase();

14
New cards

Q: How do you convert a string to lowercase in Java?

You can convert a string to lowercase using the .toLowerCase() method. Example: str.toLowerCase();

15
New cards