3 Strings Flashcards
Is the new operator required for Strings?
no, it’s optional
In a string, When does + concat and when does it perform addition?
If either operand involved in the + expression is a String, concatenation is used; otherwise, addition is used.
What are 13 methods of the String class?
cceeeilrssttt
charAt(), concat(), endsWith(), equals(), equalsIgnoreCase(), indexOf(), length(), replace(), startsWith(), substring(), toLowerCase(), toUpperCase(), and trim()
What are 10 methods of the StringBuilder class?
append(), charAt(), delete(), deleteCharAt(), indexOf(), insert(), length(), reverse(), substring(), toString().
What is the difference between StringBuilder & StringBuffer?
StringBuffer is the same as StringBuilder except that it is thread safe
What does == do with two Strings?
Calling == on String objects will check whether they point to the same object in the pool
What does == do with two StringsBuilder references?
Calling == on StringBuilder references will check whether they are pointing to the same StringBuilder object
What does equals() do on String objects?
Calling equals() on String objects will check whether the sequence of characters is the same.
What does equals() do on StringBuilder objects?
Calling equals() on StringBuilder objects will check whether they are pointing to the same object rather than looking at the values inside.
Is array size fixed on creation?
yes
What does Arrays.sort(myArray) do?
sorts an array
Arrays.binarySearch()
searches a sorted array and returns the
index of a match. If no match is found, it negates the position where the element would need to be inserted and subtracts 1.
T or F Methods that are passed varargs (…) can be used as
if a normal array was passed in.
T
Can an ArrayList contain primitives?
No, primitives must be in wrapper classes. Java will autobox parameters passed in to the proper wrapper type.
What is the method to sort an ArrayList?
Collections.sort()