OCP 17 Exam - chapter 4 notes
Chapter 4 notes
- be aware that exam want to trick us on concatenation of
String
and numbers, e.g. prints66
1
2
3
int five = 5;
String six = "6";
System.out.println(1 + five + six);
String#substring
accepts numbers/indexes from0
to length of String, e.g.
1
2
3
4
var text = "abcdef";
System.out.println(text.substring(0, 6)); // prints abcdef
System.out.println(text.substring(6, 6)); // prints ""
// System.out.println(text.substring(0, 7)); // throws java.lang.StringIndexOutOfBoundsException
equals
andhashcode
is not required on exam, but be aware that ifequals
is implemented then both should be consistent to avoid collisions in “hash” based collectionsString#contains
is just convenience method insteadstring.indexOf(otherString) != -1
String#trim
removes only ` \t\n\r, but
String#stripremoves also Unicode whitespace, e.g.
\u2000`String#ident
… TODO
Blog post not finished
Playground code
https://github.com/RG9/rg-playground-ocp17/blob/main/Chapter4.java
This post is licensed under CC BY 4.0 by the author.