The Java API
and the String Class


Overview

The Java API (Application Programming Interface)

The String Class

Goals


Part 1: Tour the API


Part 2: API Explained



JavaTM 2 Platform
Standard Ed. 5.0

Packages

java.applet
...
java.util
...
Overview    ...    Tree    Index    Help
java.lang
Class String

 

Field Summary
 
Constructor Summary
Classes

AbstractAction
...
ArrayList
...
Character
...
Comparable
...
LinkedList
...
List
...
Math
...
Random
...
Scanner
...
String
...
 
Method Summary
char charAt(int index)
   
int compareToIgnoreCase(String str)
   
boolean contains(CharSequence s)
   
boolean equals(Object anObject)
boolean equalsIgnoreCase(String anotherString)
   
int indexOf(int ch)
   
int length()
   
String replaceAll(String regex, String replacement)
   
String[] split(String regex)


Part 3: String Class

Some code (and questions) utilizing the String class's methods:

String s1 = "Popsicle";
String s2 = "Gibraltar";

int r1 = s2.indexOf("alt");
String r2 = s1.substring(0,3);
s1.concat(" time!");
char c = s1.charAt(5);
What are the values of r1, r2, s1, and c after those 6 lines of code run? [See bottom of page for answers.]

Answers to questions:

r1 = 4
r2 = "Pop" //Remember, substring(x,y) is all characters after and including x that appear before y.
s1 = "Popsicle" //Very important - Strings are immutable!  The concat method does not change s1, it returns a new String which can be assigned.
c = 'c'