• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/16

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

16 Cards in this Set

  • Front
  • Back
Array
An array is a list of data. It is possible to have an array of any type of data. Each piece of data in an array is identified by an index number representing its position in the array. The first element in the array is [0], the second element is [1], and so on. Arrays are similar to objects, so they must be created with the keyword new.

Each array has a variable length, which is an integer value for the total number of elements in the array. Note that since index numbering begins at zero (not 1), the last value in an array with a length of 5 should be referenced as array[4] (that is, the length minus 1), not array[5], which would trigger an error.

Another common source of confusion is the difference between using length to get the size of an array and length() to get the size of a String. Notice the presence of parentheses when working with Strings. (array.length is a variable, while String.length() is a method specific to the String class.)

Syntax
datatype[] var
var[element] = val
ArrayList
An ArrayList stores a variable number of objects. This is similar to making an array of objects, but with an ArrayList, items can be easily added and removed from the ArrayList and it is resized dynamically. This can be very convenient, but it's slower than making an array of objects when using many elements. Note that for resizable lists of integers, floats, and Strings, you can use the Processing classes IntList, FloatList, and StringList.

An ArrayList is a resizable-array implementation of the Java List interface. It has many methods used to control and search its contents. For example, the length of the ArrayList is returned by its size() method, which is an integer value for the total number of elements in the list. An element is added to an ArrayList with the add() method and is deleted with the remove() method. The get() method returns the element at the specified position in the list. (See the above example for context.)

Constructor
ArrayList<Type>()
ArrayList<Type>(initialCa
FloatDict
A simple class to use a String as a lookup for an float value. String "keys" are associated with floating-point values.

Methods
size()
Returns the number of key/value pairs
clear()
Remove all entries
keys()
Return the internal array being used to store the keys
keyArray()
Return a copy of the internal keys array
values()
Return the internal array being used to store the values
valueArray()
Create a new array and copy each of the values into it
get()
Return a value for the specified key
set()
Create a new key/value pair or change the value of one
hasKey()
Check if a key is a part of the data structure
add()
Add to a value
sub()
Subtract from a value
mult()
Multiply a value
div()
Divide a value
remove()
Remove a key/value pair
sortKeys()
Sort the keys alphabetically
sortKeysReverse()
Sort the keys alphabetially in reverse
sortValues()
Sort by values in ascending order
sortValuesReverse()
Sort by values in descending order
FloatList
Helper class for a list of floats. Lists are designed to have some of the features of ArrayLists, but to maintain the simplicity and efficiency of working with arrays.

Functions like sort() and shuffle() always act on the list itself. To get a sorted copy, use list.copy().sort().

Constructor
FloatList()
HashMap
A HashMap stores a collection of objects, each referenced by a key. This is similar to an Array, only instead of accessing elements with a numeric index, a String is used. (If you are familiar with associative arrays from other languages, this is the same idea.) The above example covers basic use, but there's a more extensive example included with the Processing examples. In addition, for simple pairings of Strings and integers, Strings and floats, or Strings and Strings, you can now use the simpler IntDict, FloatDict, and StringDict classes.

Constructor
HashMap<Key, Value>()
HashMap<Key, Value>(initialCapacity)
HashMap<Key, Value>(initialCapacity, loadFactor)
HashMap<Key, Value>(m)
IntDict
A simple class to use a String as a lookup for an int value. String "keys" are associated with integer values.

Example
IntDict inventory;

void setup() {
size(200, 200);
inventory = new IntDict();
inventory.set("cd",84);
inventory.set("tapes",15);
inventory.set("records",102);
println(inventory);
noLoop();
fill(0);
textAlign(CENTER);
}

void draw() {
int numRecords = inventory.get("records");
text(numRecords, width/2, height/2);
}

Constructor
IntDict()
IntList
Helper class for a list of ints. Lists are designed to have some of the features of ArrayLists, but to maintain the simplicity and efficiency of working with arrays.

Functions like sort() and shuffle() always act on the list itself. To get a sorted copy, use list.copy().sort().

Constructor
IntList()
JSONArray
A JSONArray stores an array of JSON objects. JSONArrays can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk,

Example
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
String[] names = { "Goat", "Leopard", "Zebra" };

JSONArray values;

void setup() {

values = new JSONArray();

for (int i = 0; i < species.length; i++) {

JSONObject animal = new JSONObject();

animal.setInt("id", i);
animal.setString("species", species[i]);
animal.setString("name", names[i]);

values.setJSONObject(i, animal);
}

saveJSONArray(values, "data/new.json");
}

// Sketch saves the following to a file called "new.json":
// [
// {
// "id": 0,
// "species": "Capra hircus",
// "name": "Goat"
// },
// {
// "id": 1,
// "species": "Panthera pardus",
// "name": "Leopard"
// },
// {
// "id": 2,
// "species": "Equus zebra",
// "name": "Zebra"
// }
// ]
JSONObject
A JSONObject stores JSON data with multiple name/value pairs. Values can be numeric, Strings, booleans, other JSONObjects or JSONArrays, or null. JSONObject and JSONArray objects are quite similar and share most of the same methods; the primary difference is that the latter stores an array of JSON objects, while the former represents a single JSON object.

JSON can be generated from scratch, dynamically, or using data from an existing file. JSON can also be output and saved to disk, as in the example above.

Example
JSONObject json;

void setup() {

json = new JSONObject();

json.setInt("id", 0);
json.setString("species", "Panthera leo");
json.setString("name", "Lion");

saveJSONObject(json, "data/new.json");
}

// Sketch saves the following to a file called "new.json":
// {
// "id": 0,
// "species": "Panthera leo",
// "name": "Lion"
// }
Object
Objects are instances of classes. A class is a grouping of related methods (functions) and fields (variables and constants).

Syntax
ClassName instanceName

Example
// Declare and construct two objects (h1, h2) from the class HLine
HLine h1 = new HLine(20, 2.0);
HLine h2 = new HLine(50, 2.5);

void setup()
{
size(200, 200);
frameRate(30);
}

void draw() {
background(204);
h1.update();
h2.update();
}

class HLine {
float ypos, speed;
HLine (float y, float s) {
ypos = y;
speed = s;
}
void update() {
ypos += speed;
if (ypos > width) {
ypos = 0;
}
line(0, ypos, width, ypos);
}
}
String
A string is a sequence of characters. The class String includes methods for examining individual characters, comparing strings, searching strings, extracting parts of strings, and for converting an entire string uppercase and lowercase. Strings are always defined inside double quotes ("Abc"), and characters are always defined inside single quotes ('A').

To compare the contents of two Strings, use the equals() method, as in if (a.equals(b)), instead of if (a == b). A String is an Object, so comparing them with the == operator only compares whether both Strings are stored in the same memory location. Using the equals() method will ensure that the actual contents are compared. (The troubleshooting reference has a longer explanation.)

Because a String is defined between double quotation marks, to include such marks within the String itself you must use the \ (backslash) character. (See the third example above.) This is known as an escape sequence.
StringDict
A simple class to use a String as a lookup for an String value. String "keys" are associated with String values.
StringList
Helper class for a list of Strings. Lists are designed to have some of the features of ArrayLists, but to maintain the simplicity and efficiency of working with arrays.

Functions like sort() and shuffle() always act on the list itself. To get a sorted copy, use list.copy().sort().
Table
Table objects store data with multiple rows and columns, much like in a traditional spreadsheet. Tables can be generated from scratch, dynamically, or using data from an existing file. Tables can also be output and saved to disk, as in the example above.

Constructor
Table()
Table(rows)

Example
Table table;

void setup() {

table = new Table();

table.addColumn("id");
table.addColumn("species");
table.addColumn("name");

TableRow newRow = table.addRow();
newRow.setInt("id", table.lastRowIndex());
newRow.setString("species", "Panthera leo");
newRow.setString("name", "Lion");

saveTable(table, "data/new.csv");
}

// Sketch saves the following to a file called "new.csv":
// id,species,name
// 0,Panthera leo,Lion
TableRow
A TableRow object represents a single row of data values, stored in columns, from a table.

Example
Table table;

void setup() {

table = new Table();

table.addColumn("number", Table.INT);
table.addColumn("mass", Table.FLOAT);
table.addColumn("name", Table.STRING);

TableRow row = table.addRow();
row.setInt("number", 8);
row.setFloat("mass", 15.9994);
row.setString("name", "Oxygen");

println(row.getInt("number")); // Prints 8
println(row.getFloat("mass")); // Prints 15.9994
println(row.getString("name")); // Prints "Oxygen
}
XML
XML is a representation of an XML object, able to parse XML code. Use loadXML() to load external XML files and create XML objects.

Only files encoded as UTF-8 (or plain ASCII) are parsed properly; the encoding parameter inside XML files is ignored.

Constructor
XML(name)

Example
// The following short XML file called "mammals.xml" is parsed
// in the code below. It must be in the project's "data" folder.
//
// <?xml version="1.0"?>
// <mammals>
// <animal id="0" species="Capra hircus">Goat</animal>
// <animal id="1" species="Panthera pardus">Leopard</animal>
// <animal id="2" species="Equus zebra">Zebra</animal>
// </mammals>

XML xml;

void setup() {
xml = loadXML("mammals.xml");
XML[] children = xml.getChildren("animal");

for (int i = 0; i < children.length; i++) {
int id = children[i].getInt("id");
String coloring = children[i].getString("species");
String name = children[i].getContent();
println(id + ", " + coloring + ", " + name);
}
}

// Sketch p