This is a Premium Document. Some documents on Studocu are Premium. Upgrade to Premium to unlock it.

AP Computer Science A Java Quick Reference

University: Harvard University

Course: Introduction to Computer Science (CS 50)

360 Documents

Students shared 360 documents in this course

This is a preview

Do you want full access? Go Premium and unlock all pages

  • Access to all documents

  • Get Unlimited Downloads

  • Improve your grades

Already Premium?

Java Quick Reference

Accessible methods from the Java library that may be included in the exam

Class Constructors and Methods Explanation

String Class

String(String str) Constructs a new String object that represents the same sequence of

characters as str

int length() Returns the number of characters in a String object

String substring(int from,

int to)

Returns the substring beginning at index from and ending at index to – 1

String substring(int from) Returns substring(from, length())

int indexOf(String str) Returns the index of the first occurrence of str; returns -1 if not found

boolean equals(String other) Returns true if this is equal to other; returns false otherwise

int compareTo(String other) Returns a value <0 if this is less than other; returns zero if this is

equal to other; returns a value >0 if this is greater than other

Integer Class

Integer(int value) Constructs a new Integer object that represents the specified int value

Integer.MIN_VALUE The minimum value represented by an int or Integer

Integer.MAX_VALUE The maximum value represented by an int or Integer

int intValue() Returns the value of this Integer int

Double Class

as an

Double(double value) Constructs a new Double object that represents the specified double value

double doubleValue() Returns the value of this Double as a double

Math Class

Returns the absolute value of an int value

Returns the absolute value of a double value

Returns the value of the first parameter raised to the power of the second

parameter

Returns the positive square root of a double value

Returns a double value greater than or equal to 0.0 and less than 1.0

ArrayList Class

int size() Returns the number of elements in the list

boolean add(E obj) Appends obj to end of list; returns true

void add(int index, E obj) Inserts obj at position index (0 <= index <= size), moving

elements at position index and higher to the right (adds 1 to their indices) and

adds 1 to size

E get(int index) Returns the element at position index in the list

E set(int index, E obj) Replaces the element at position index with obj; returns the element

formerly at position index

E remove(int index) Removes element from position index, moving elements at position

index + 1 and higher to the left (subtracts 1 from their indices) and subtracts 1

from size; returns the element formerly at position index

Object Class

boolean equals(Object other)

String toString()

00762-118-CED-CSA_Appendix.indd 209 4/12/19 8:50 PM

AP Computer Science A Course and Exam Description

Return to Table of Contents

© 2019 College Board

Appendix V.1

|

209

static int abs(int x)

static double abs(double x)

static double pow(double

base, double exponent)

static double sqrt(double x)

static double random()

You are watching: AP Computer Science A Java Quick Reference. Info created by GBee English Center selection and synthesis along with other related topics.