Iteration in Programming
Which data structure is most suitable for storing unique words read from a large document while optimizing for fast membership checking?
TreeMap
HashSet
LinkedList
ArrayList
What does the expression "computer".charAt(0) return?
"c"
'c'
"comp"
'computer'
Which loop correctly finds and prints all substrings of length three from a non-empty String variable named 'text'?
for(int j=0;j<text.length()-2;j++){System.out.println(text.charAt(j)+""+text.charAt(j+1)+text.charAt(j+2));}
for (int i = 0; i <= text.length() -3 ;i++){System.out.println(text.substring(i,i+3));}
for (int i=3;i<=text.length();i++){System.out.println(text.substring(i-3,i));}
for (int i=2;i<text.length();i++){System.out.println(text.substring(i-2,i));}
Which method call would correctly replace all occurrences of 'x' with 'o' in a String variable named myString?
myString.replaceChar('x', 'o');
myString.replace('x', 'o');
myString.replaceAll('x', 'o');
myString.replaceString('x', 'o');
How does the "Reversing a String" algorithm work?
It finds the longest palindrome substring in a string
It removes all vowels from a string
It reverses the characters in a string by iterating through each character
It converts all lowercase letters to uppercase and vice versa
Given String s
, which option will reverse its characters most efficiently?
char[] chars=s.toCharArray();Arrays.sort(chars);String reversedStr=new String(chars);
String reversedStr="";for(int i=0;i<s.length();++i){reversedStr=s.charAt(i)+reversedStr;}
StringBuilder sb = new StringBuilder(s); sb.reverse(); String reversedStr=sb.toString();
List
Given a method compressString(String original)
that reduces consecutive identical characters to a single character, which implementation efficiently handles strings of any length?
Creates an array of booleans representing each ASCII value, toggling presence or absence for each char in the string.
Recursively replaces all adjacent pairs of similar chars with a single one until no such pair exists.
Uses regular expressions to find repeated characters and removes duplicates with backreferences.
Loops through the string, appending non-repeated chars or the first char of a sequence to a StringBuilder.

How are we doing?
Give us your feedback and let us know how we can improve
Which statement about string literals in Java is true?
String literals are interned by Java for memory efficiency.
String literals can be changed after they are created using standard string methods.
Two distinct string literals always result in two different String objects.
It's necessary to manually allocate memory for storing string literals with new operator.
How do you convert all characters in a string 'text' to Upper Case?
Uppercase.text()
text.toUpperCase()
text.toUpper()
makeUpperCase(text)
What scenario best justifies using composition over inheritance when designing two classes, 'LineEditor' with basic editing features, and 'AdvancedEditor', needing additional string processing capabilities?
When all instances of LineEditors should automatically gain new features added later to AdvancedEditors.
When both editors share common state that should be kept consistent across both classes.
When AdvancedEditors are specialized types of LineEditors with added methods.
When AdvancedEditor should have LineEditor’s functionalities but isn’t conceptually a subtype.