Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-09-15 HW

posted Sep 15, 2017, 9:59 AM by Samuel Konstantinovich   [ updated Sep 15, 2017, 10:06 AM ]
Java Strings

Java Documentation:
http://docs.oracle.com/javase/8/docs/api/

Strings are not primitives, they are Objects. 

Operations that work on strings:
+    concatenation 

You cannot use == ,  >, <= etc for comparison.

They contain methods! (You saw python string methods!

Strings:
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html

AP Critical Methods:
substring  : like a python slice
equals  :  determining identical contents
compareTo : for less than/ greater than / equal  comparison
length

Escape Sequences:
Special characters sometimes need to go in strings, but cannot be typed. 
We can put them in strings using the backslash to escape the character from being treated like a regular symbol. 
This works in both char and String types.

\n is the newline character, so you can write literals like:  '\n'  ,  "'\n" ,  or "fish\nfood"
\t  tab
\'  single quote
\"  double quote
\\ backslash

System.out.println("\\why\no//\"!\'?")  would print:

\why
o//"!'?

Each escaped character counts as 1 unit for the length of the string and charAt and substring treat them as single characters (only we see 2, the views these symbols as 1 thing each)


Class Critical Methods:
charAt   


Literal Strings
String variables


Homework:
http://codingbat.com/java/String-1
makeTags 
makeOutWord 
extraEnd 
firstTwo
withoutX
Comments