Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

String - Using functions in combination

 

Functions

String - Using functions in combination

We can compose functions - this is where one function is applied to another.

1. [ Java ] substring and equals


Big

Show the name where the second and fourth letters for countries with short names.

Burundi

  • We use substring to extract the required characters
  • We must use .equals to compare the strings == will NOT work.

2. [ Java ] substring with length


Big

Extract the last two characters from the name of a country.

  • The last character in String s has index s.length()-1
  • The character before this is at s.length()-2

3. [ Java ] toLowerCase and endsWith


Big

Show the countries where the first and last letters are the same (irrespective of case).

  • The first letter is in name.substring(0,1), we turn this to lower case.