Lecture 10 - String Tokenizer, Immutable - Wrapper - Classes
Lecture 10 - String Tokenizer, Immutable - Wrapper - Classes
CS F213
J. Jennifer Ranjani
email: [email protected]
BITS Pilani
Pilani Campus
String Tokenizer
User defined
immutable classes
BITS Pilani
Wrapper classes
Pilani Campus
BITS Pilani
Pilani Campus
String Tokenizer
String Tokenizer
• java.util.StringTokenizer class allows you to break a
string into tokens
• default delimiter set, which is " \t\n\r\f" : the space character, the tab character,
the newline character, the carriage-return character, and the form-feed character.
Constructor Description
StringTokenizer(String str) creates StringTokenizer with
specified string.
StringTokenizer(String str, String creates StringTokenizer with
delim) specified string and delimeter.
StringTokenizer(String str, String creates StringTokenizer with
delim, boolean returnValue) specified string, delimeter and
returnValue. If return value is true,
delimiter characters are considered
to be tokens. If it is false, delimiter
characters serve to separate tokens.
Output:
abc,def,ghi
Output:
abc
• A parameterized constructor
• No setters
• To not have option to change the value of the instance variable
int getAcc(){
return acc;}
String getName() {
return name; }
float getAmount() {
return amount; }
System.out.println(a);
Output:
a.amount = 1000;
Exception in thread "main" java.lang.Error:
}}
Unresolved compilation problem:
The final field Account.amount cannot be
assigned
Wrapper Classes
Wrapper Class
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
Autoboxing and
Unboxing (Java 5)
Wrapper Class & Boxing -
Example
int a = 50;
Integer i = Integer.valueOf(60); Output:
Integer j = a; // auto boxing -1
System.out.println(j.compareTo(i));