0% found this document useful (0 votes)
20 views5 pages

Library classes

The document provides an overview of Java's Wrapper Classes, detailing their functions, boxing and unboxing processes, and conversion functions. It also introduces the Scanner Class, which facilitates input of primitive data types and strings. Various methods of the Scanner Class are outlined for reading different data types.

Uploaded by

Mark wahlburger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Library classes

The document provides an overview of Java's Wrapper Classes, detailing their functions, boxing and unboxing processes, and conversion functions. It also introduces the Scanner Class, which facilitates input of primitive data types and strings. Various methods of the Scanner Class are outlined for reading different data types.

Uploaded by

Mark wahlburger
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Library Classes

Wrapper Class: Wrapper class is a part of standard library java.lang


package provides many methods to manipulate primitive data type in a
program.
Function of Wrapper Class:
✓ It determines the nature of primitive data type.
✓ It converts primitive data type to its object.
✓ It converts object data into data of primitive data type.

Wrapper Classes of Java:


Data Type Wrapper Class

byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
Boxing and Unboxing:

Boxing:- Converting a primitive value into an object of


the corresponding wrapper class by calling its constructor
is called boxing. Example:- int a=43;
Integer a2=new Integer(a);//Boxing

Autoboxing:- Converting a primitive value into an object of the


corresponding wrapper class automatically is called autoboxing.
Example
char x=’a’;
Character g = x; //Auto Boxing

Unboxing: Converting an object of a wrapper type to its


corresponding primitive value by using casting is called
unboxing.
Example:-
Character g = 'a';
char ch2=(char)g; //Unboxing

Auto unboxing: Converting an object of a wrapper type to its


corresponding primitive value automatically is called unboxing.
Example:-
Character g = 'a';
char ch1 = g; //Auto unboxing
Conversion Function: Those functions that converts numeric data into
string data and vice-verse are known as conversion function. These
functions are as follows:
1) toString(): It is used to convert the numeric value passed as
argument into string object. Ex: int y=25;
String s=Integer.toString(y);
2) parse: This keyword is used to convert the numeric type string
(“1234”) into corresponding primitive data type (numeric type).
Ex:
String s=”345”;
int x=Integer.parseInt(s);
3) valueOf(): This function is used to convert the numeric type string
passed as argument into corresponding primitive data type object.
Ex: String s=”125”;
int x=Integer.valueOf(s); Character
Function:

Function Syntax Result


1) isLetter(char ch)
Character.isLetter(char ch) true if ch is a letter
otherwise false
2) isDigit(char ch)
Character.isDigit(char ch) true if ch is a digit
otherwise false

3) isLetterOrDigit(char Character.isLetterOrDigit(char true if ch is a letter or


ch) ch) digitotherwise false
4) isWhitespace(char
ch) Character.isWhitspace(char true if ch is
ch) space/blank otherwise
false

5) toLowerCase(char Character.toLowerCase(char it converts ch into


ch) ch) lower case
6) isUpperCase(char ch) Character.isUpperCase(char
ch) true if ch is upper case
otherwise false.

7) isLowerCase(char ch) Character.isLowerCase(char


ch) true if cha is lower
case otherwise false.

8) toUpperCase(char ch) Character.toUpperCase(char


ch) it converts ch into
upper case.

Scanner Class: The class that allows to input or read primitive data types
and string is known as Scanner Class. It can be used to get input from
InputStream. The scanner class is a part of java.util package. This class
has many built functions. To use Scanner class java.util package must be
imported. Syntax:
import java.util.*; or import java.util.Scanner;
The following syntax declares Scanner class and creates its object.
Scanner sc= new Scanner(System.in);
Here Scanner is a class, sc is an object name, System.in an InputStream.
Functions of Scanner Class:
nextInt() This function is used to input an
integer value.
nextLong() This function is used to input a long
integer value.
nextFloat() This function is used to input a
float value.
nextDouble() This function is used to input a
double value.
next() This function is used to input a
single word without space.

nextLine() This function is used to input a line


with or without space.

next().charAt(0) This function is used to input a


single character

You might also like