1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
All Flashcards
What is a substring?
A sequence of characters within a larger string.
What is a zero-indexed language?
A language where counting starts at 0, not 1.
What does the length()
method do?
Returns the number of characters in a string.
What does the substring()
method do?
Returns a substring of a string.
What does the equals()
method do?
Checks if two strings have the same characters in the same order (case-sensitive).
What does the compareTo()
method do?
Compares two strings lexicographically (alphabetical order).
What is an external library?
A collection of pre-written code for common tasks.
What is an API?
A set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service.
What is the purpose of Java documentation?
To list available methods and how to use them for a Java class, library, or API.
What is the java.lang
package?
A package in Java that contains core classes; classes in this package are automatically imported.
What does the following code output?
java
String str = "Hello";
int len = str.length();
System.out.println(len);
5
What does the following code output?
java
String str = "Peter Cao";
String sub1 = str.substring(0, 5);
System.out.println(sub1);
Peter
What does the following code output?
java
String str1 = "hello";
String str2 = "Hello";
boolean isEqual = str1.equals(str2);
System.out.println(isEqual);
false
What does the following code output?
java
String str1 = "apple";
String str2 = "banana";
int result = str1.compareTo(str2);
System.out.println(result > 0);
false
What does the following code output?
java
String s6 = "hello world";
int pos = s6.indexOf("l");
System.out.println(pos);
2
What does the following code output?
java
String s3 = "cat";
String s2 = s3.substring(1,3);
System.out.println(s2);
at
What does the following code output?
java
String s5 = "Blue";
String s6 = "Blue";
int answer = s5.compareTo(s6);
System.out.println(answer);
0
What does the following code output?
java
String str = "Coding";
String sub = str.substring(1, 4);
System.out.println(sub);
odi
What does the following code output?
java
String text = "programming";
int index = text.indexOf("m");
System.out.println(index);
7
What does the following code output?
java
String s4 = "hello";
String s2 = s4.substring(3);
System.out.println(s2);
lo
Why is string manipulation important?
It allows you to process, modify, and extract information from text data.
What is the significance of zero-indexing in Java?
It affects how you access characters and substrings within a string.
How does equals()
differ from using ==
for string comparison?
equals()
compares the content of the strings, while ==
compares the memory addresses.
What does lexicographical order mean?
Alphabetical order, considering character encoding (e.g., ASCII or Unicode).
What is the purpose of using external libraries and APIs?
To extend Java's capabilities with pre-written code, saving time and effort.
Why is understanding Java documentation important?
It provides essential information on how to use classes, methods, and APIs correctly.
How do you access the nth character of a string?
Use str.substring(n-1, n)
due to zero-indexing.
What is the return type of the length()
method?
int
What is the return type of the equals()
method?
boolean
What is the return type of the compareTo()
method?
int