1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Q: What is an array in Java?
An array is a container object that holds a fixed number of values of a single type.
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];
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};
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
.
Q: How do you access an array element?
You access an array element using its index. Example: arr[0] accesses the first element.
Q: What is a multidimensional array in Java?
A multidimensional array is an array of arrays. Example: int[][] matrix = new int[3][3];
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.
Q: How do you declare a String in Java?
You declare a String by using the String
keyword. Example: String str = "Hello";
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.
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".
Q: How do you compare strings in Java?
You compare strings using the .equals()
method for content equality or ==
for reference equality.
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.
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();
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();