String Class Flashcards
Difference between “==” and equals()
”==” is a binary operator, used to compare primitives and sometimes objects, but with objects compares the memory reference.
equals() is a method, used for checking equality of two objects defined by business logic
Difference between String vs StringBuilder vs StringBuffer
String Class is inmutable
StringBuilder is mutable but not thread-safe
StringBuffer is mutable and thread-safe
Access Level «protected»
Same class, same package, sub class in another package
Access Level «defalut»
Same class, same package
Access Level «private»
Same class
Access Level «public»
Anyplace
static Keyword
- Can be used without object instances
- Used when the problem is best solved without object
- Used when objects of the same type need to share fields
static Methods
- Are called class
- Are useful for APIs that are not object oriented
- Are commonly used in place of constructors to perform tasks related to object initialization
Difference between Abstract class and interface
Abstract class usually contains at least one abstract method, cannot be instantied Interface contains only abstract methods, cannot be instantied
Features of list interface
- Is an ordered collection of elements Behaviors - Adding, getting, removing and overwriting elements at a specific index - Getting the size of the list - Allows duplicate elements - Ordered
Features of set interface
- Contains only unique elements
- Has no index
- Duplicate elements are not allowed
- You can iterate through elements to access them
- TreeSet provides sorted implementation
- Unordered
Features of map interface
- Stores multiple key-value pairs, key is unique and associated to the value.
Features of deque interface
- Can be used as a stack or a queue
- Like a deck
- A Queue provides FIFO operations add, remove.
- A Stack provides LIFO operaions, push and pop
Features of comparable interface
- Overrides the compareTo method
- Provides only one sort option
- Collections.sort(collection)
Features of comparator interface
- Implemented by using compare method
- Enables you to create multiple comparator classes
- Enables you to create and use numerous sorting options
- Collections.sort(collection, comparator class)