APIs Flashcards
Does calling a method change a String?
ex.: “1234”.replace(‘1’, ‘9’);
No.
Strings are immutable. Calling methods does not change the object, it creates a new String object.
Can you extend String class?
No.
Not because it is immutable, but because it is final.
Can StringBuffer or StringBuilder be extended?
No.
They are final classes.
Can Wrapper classes be extended?
No.
They are final classes.
Does the String class have a method called reverse?
No.
But StringBuilder and StringBuffer do.
How do you represent just a date with no time zone information?
java.time.LocalDate
What are common classes of the java.time package?
LocalDate, LocalTime, LocalDateTime, Instant, Period, Duration are part of this package.
How do you get time zone information?
Use ZonedDateTime
How do you format Date objects?
java.time.format.DateTimeFormatter
LocalDate d1 = LocalDate.parse(“2015-01-01”, DateTimeFormatter.ISO_LOCAL_DATE);
If using ArrayList API, what happens if the fromIndex and toIndex arguments of a subList ( ) method are equal?
The subList returns an empty list.
List foo - new ArrayList( ); foo.add("f"); foo.add("o"); foo.add("o"); List bar = new ArrayList( foo.subList(1, 1) );
T/F: Literal strings within the same class in the same package represent references to the same String object.
True.
T/F: Literal strings within different classes in the same package represent references to the same String object.
True.
When do Strings that are computed by constant expressions actually get computed?
At compile time.
How are Strings computed by constant expressions treated?
When computed at compile time, they are treated as if they were literals.
What does the java string intern( ) method do?
It returns the interned (canonical representation) of string.