Builtinin Classes in java.lang and java.util - PowerPoint PPT Presentation


PPT – Builtinin Classes in java.lang and java.util PowerPoint presentation | free to download - id: 11a84b-ODdmN


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Builtinin Classes in java.lang and java.util


static int parseInt(String s, int radix) static Integer valueOf(String s) ... static int digit(char c, int radix) static int getNumericValue(char c) ... – PowerPoint PPT presentation

Number of Views:281
Avg rating:3.0/5.0
Slides: 14
Provided by: davidj77
Tags: builtinin | classes | java | lang | radix | util


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Builtinin Classes in java.lang and java.util

Builtin-in Classes in java.lang and java.util
  • Wrapper Classes
  • Boolean, Character, Byte, Short, Integer
  • Long, Float, Double
  • String StringBuffer
  • Vector
  • LinkedList
  • Hashtable

Wrapper Classes
Wrapper class Primitive Boolean boolean Charact
er char Byte byte Short short Integer int
Long long Float float Double double
The Integer Class
  • Convert to different types
  • Parse integer strings

byte byteValue() double doubleValue() float
floatValue() int intValue() long longValue()
short shortValue() String toString()
static String toBinaryString(int value) static
String toHexString(int value) static String
toOctalString(int value) static
String toString(int value) static
String toString(int value, int radix)
static Integer decode(String s) static int
parseInt(String s) static int
parseInt(String s, int radix) static Integer
valueOf(String s) static Integer
valueOf(String s, int radix)
Using the Integer Class
public class TestStack public static void
main(String args) Stack s new Stack()
int i s.push(new Integer(1))
s.push(new Integer(2)) i
The Character Class
char charValue() static int digit(char c, int
radix) static int getNumericValue(char c)
static boolean isDigit(char c) static boolean
isLetter(char c) static boolean
isLetterOrDigit(char c) static boolean
isLowerCase(char c) static boolean
isSpaceChar(char c) static boolean
isUpperCase(char c) static char
toLowerCase(char c) String toString() static
char toUpperCase(char c)
The String Class
  • Defined in java.lang.
  • All string literals are immutable instances of
  • Important Identical literals have the same
    object reference.
  • Useful methods include
  • charAt, equals, length, startsWith, indexOf,
    toLowerCase, etc.

String Comparisons
  • Several ways to compare two String objects
  • compareTo, equals, equalsIgnoreCase.
  • Never use to test for content equality between
  • This only gives reference equality.

The Immutability of Strings
  • We often construct new strings out of existing
    strings, e.g., using .
  • Because String objects are immutable, we always
    obtain a new instance
  • String noun "dog"
  • noun "s"
  • Similarly with concat, etc.

Parsing Strings
public int countSpaces(String s) int count
0 // Look for the first. int index
s.indexOf(' ') // indexOf returns -1 on
failure. while(index gt 0) // We
found one. count 1 // Look
for the next just after the last one.
index s.indexOf(' ',index1) return
Strings from Primitive Values
  • Direct assignment is illegal
  • String s 32 // Forbidden.
  • Implicit type conversion is common
  • String s ""num
  • Via the static valueOf method
  • String s String.valueOf(num)

The StringBuffer Class
  • String-like objects that are mutable.
  • Used for building a String out of multiple
  • Size is dynamic and unlimited.

StringBuffer append(xxx arg) where xxx can be
any primitive type or objet type StringBuffer
insert(int offset, xxx obj) int capacity() char
charAt(int index) int length() void
setCharAt(int index,char ch) StringBuffer
Formatting an Integer
public String formatInt(int number,int width)
// Create space for the full width.
StringBuffer formattedInt
new StringBuffer(width) // Append a
string version of the number.
formattedInt.append(number) // How many
extra spaces are required? int spaces
width-formattedInt.length() for(int i 0
i lt spaces i) formattedInt.insert(0,"
") return formattedInt.toString()
About PowerShow.com