Você está na página 1de 4

JAVA METHODS

Methods in class Math


Return type

Method name

Description

static double

Math.abs(double a)

The absolute value of a number

static double

Math.max(double a, double b)

The greater of two numbers

static double

Math.min(double a, double b)

The smaller of two numbers

static double

Math.pow(double a, double b)

The number a raised to the power b

static double

Math.random()

A random number a such that 0 a < 1

static long

Math.round(double a)

The closest integer value

static double

Math.sqrt(double a)

The square root

static double

Math.PI

The number (= 3.14159...)

Character Methods
Return type

Method name

Description

static boolean

isDigit(char c)

Determines if the character is a digit

static boolean

isLetter(char c)

Determines if the character is a letter

static boolean

isLetterOrDigit(char c)

Determines if the character is a letter or a digit

static boolean

isWhitespace(char c)

Determines if the character is a space or EndOfLine

static char

toLowerCase(char c)

Converts to lower case

static String

toString(char c)

Converts to a string

static char

toUpperCase(char c)

Converts to upper case

Wrapper Classes
Return type

Method name

Description

Integer

Integer(int value)

Constructor for class Integer

int

intValue()

Returns the value stored in this Integer object

static int

parseInt(String s)

Converts a string to an integer value

Double

Double(double value)

Constructor for class Double

double

doubleValue()

Returns the value stored in this Double object

static double

parseDouble(String s)

Converts a string to a double value

Boolean

Boolean(boolean value)

Constructor for class Boolean

Character

Character(char value)

Constructor for class Character

String Methods
Return type

Method name

Description

char

charAt(int index )

Returns the character at the specified index

int

compareTo(String str )

Compare two strings: Returns -1, 0, 1 for <, =, >

int

compareToIgnoreCase(String str )

As for compareTo, but ignore case of characters

boolean

equals(String str )

True if str is equals this string; false otherwise

boolean

equalsIgnoreCase(String str )

As for equals, but ignore case of characters

int

indexOf(String str )

Index of the first occurrence of str ; -1 if not present

int

indexOf(String str , int fromIndex )

Same as indexOf, but starting at index fromIndex

int

lastIndexOf(String str )

Same as indexOf, backwards from end of string

int

lastIndexOf(String str , int fromIndex )

Same as indexOf, backwards from index fromIndex

int

length()

Returns the number of characters in this string

String

replace(char oldChar , char newChar)

All oldChar replaced by newChar

String[ ]

split(String delim)

Splits the string into tokens around the delimiter

String

substring(int beginIndex )

Substring, from beginIndex to the end of the string

String

substring(int beginIndex , int endIndex )

Substring, from beginIndex to endIndex 1

String

toLowerCase()

All letters to lower case

String

toUpperCase()

All letters to upper case

String

trim(String str )

Removes leading and trailing blanks

Class JOptionPane (Package javax.swing)

Return type

Method name

static String

showInputDialog(String messageString)

static String

showInputDialog(String messageString, String initialValue)

static String

showInputDialog(null, String messageString, String titleString, String messageType)

static void

showMessageDialog(null, String outputString)

static void

showMessageDialog(null, String outputString, String titleString, String messageType)

where messageType is one of the following:


JOptionPane.INFORMATION MESSAGE

JOptionPane.ERROR MESSAGE

JOptionPane.QUESTION MESSAGE

JOptionPane.PLAIN MESSAGE

JOptionPane.WARNING MESSAGE

Input Using BufferedReader (Package java.io)

Return type

Method name

BufferedReader

BufferedReader(new InputStreamReader(System.in))

BufferedReader

BufferedReader(new FileReader(filename))

String

readLine()
if (line == null) break

Creating and Writing a Text File (Package java.io)

Return type

Method name

PrintWriter

PrintWriter(new FileWriter(filename))

void

println(String line)

void

close()

The Scanner Class (Package java.util)


Return type

Method name

Description

Scanner

Scanner(System.in)

Constructor: Scans the keyboard for input

Scanner

Scanner(String str )

Constructor: Scans a string for tokens

Scanner

Scanner(new File(fileName))

Constructor: Scans a text file for input

void

useDelimiter(String delim)

Sets a delimiter for tokens (default is white space)

String

next()

Returns next token as a String

int

nextInt()

Returns next token as an int

double

nextDouble()

Returns next token as a double

String

nextLine()

Returns the rest of the current line

boolean

hasNext()

Returns True if there are more tokens available

boolean

hasNextline()

Returns True if there are more lines to read

void

close()

Closes the scanner

The StringTokenizer Class (Package java.util)


Return type

Method name

Description

StringTokenizer

StringTokenizer(String str )

Constructs a tokenizer for string str with


delimiters space, tab, new line

StringTokenizer

StringTokenizer(String str, String delims)

Constructs a tokenizer for string str with


specified delimiters

boolean

hasMoreTokens()

Returns true if there are more tokens available

String

nextToken()

Returns the next token

int

countTokens()

Returns the number of tokens in the string


3

The Arrays Class (Package java.util)


Return type

Method name

Description

static void

sort(Object[ ] arr )

Sorts the array into ascending order

The ArrayList Class (Package java.util)


Return type

Method name

Description

ArrayList

ArrayList()

Default constructor; initial capacity 10;


size is doubled when list grows

ArrayList

ArrayList(int capacity)

Constructs a list with specified capacity

void

add(Object obj )

Appends an object to the end of the list

void

add(int i , Object obj )

Inserts an object at the specified position


(index starts at 0)

void

set(int i , Object obj)

Replaces an object at the specified position

Object

get(int i )

Returns the object at the specified position

void

remove(int i )

Removes the object at the specified position

int

size()

Returns the number of objects in the list

Você também pode gostar