ICS3U1 - Unit 3: Strings and Arrays

studied byStudied by 11 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 38

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

39 Terms

1

Strings

Important variable type that stores words and numbers, but cannot do any arithmetic operation

New cards
2

Characters

An 8 bit data type that stores a letter, number, symbol, space, etc.

New cards
3

Difference between integer, character, and string (in terms of syntax)

Integer: 3

Character: ‘3’

String: “3”

New cards
4

String Class

A class that includes numerous methods that can manipulate strings

New cards
5

str.charAt(index);

Returns a character at a specific index

New cards
6

str.length();

Finds the total length of the string (outputs an integer)

New cards
7

str.substring(int start); and str.substring(int start, int end);

Allows the Java to point at a specific index and output the remaining characters following that index.

  • Can pinpoint a start and end point

New cards
8

str.equals();

Comparing string values with another

  • Outputs a boolean value

New cards
9

str.equalsIgnoreCase();

Compares strings, but ignores the casings

  • Outputs boolean value

New cards
10

Index

A numerical assignment of each character in the string

  • Starts at 0, and is 1 less than the total length of the string

New cards
11

Errors with Indices

Since the final index is 1 less than the total length of the string, an error will occur if you input an index value greater than or less than what is there.

  • Anything < 0

  • Anything > str.length();

These are known as IndexOutofBound Errors

New cards
12

ASCII Table

American Standard Code for Information Interchange

  • A table of characters for the computer

New cards
13

Characters /w the ASCII Table

Every character is assigned a numerical value

  • Ex: ‘a’ has a value of 97

New cards
14

Case Sensitivity with Characters

Although we see ‘a’ and ‘A’ as the same letter but different casings, Java sees it as ‘97’ and ‘65’.

  • Meaning java casing matters in Java

New cards
15

Casting

Casting a data type allows Java to output either a number or a character value depending on what you ask for

New cards
16

Increments Dealing with Characters

These are not the Same:

  • letter++;

  • letter = letter + 1;

letter = letter + 1;

  • This is trying to add a character and an integer together

New cards
17

CompareTo() vs equals()

Both compare 2 different strings, however, they are slightly different

CompreTo()

  • Returns 0 if they are the same and returns less than or greater than 0 depending on the order.

  • CompareTo() analyzes it alphabetically

Equals()

  • Returns a boolean value (true or false)

New cards
18

Exception

An error that disrupts the flow of the code

New cards
19

Try-Catch Statements

A block of code that will catch any errors that may occur within the statement.

  • It will only catch the errors within the Try statement

<p>A block of code that will catch any errors that may occur within the statement.</p><ul><li><p>It will only catch the errors within the <strong>Try</strong> statement</p></li></ul>
New cards
20

Common use of Try-Catch Statements

InputMismatch Error

  • This is when the use inputs a different variable type than the one that is needed.

New cards
21

Exception-Handler

A try-catch statement is broken up into 2 parts

Try - Exception

  • The block of code that is being checked for errors

Catch - Exception Handler

  • Catches the error and handles it

New cards
22

Array

A data structure that can hold multiple of the same data type together.

New cards
23

Elements

This is the data within the array

New cards
24

Difference between variable and an array

An array points to a memory location which is why it is known as an object.

  • If we simply print the array, it will output the memory address of the array

New cards
25

How does an array work

An array splits up the elements using indices. Just like a string, every element has an index assigned to it.

New cards
26

Different parts of an array

int[] grades = new int[20];

Data Type: int

Array indicator: []

Name: Grades

Size: [20]

<p>int[] grades = new int[20];</p><p><strong>Data Type:</strong> int</p><p><strong>Array </strong>indicator: []</p><p><strong>Name:</strong> Grades</p><p><strong>Size: </strong>[20]</p>
New cards
27

Syntax to Declare

int[] marks;

marks = new int[5];

<p>int[] marks;</p><p>marks = new int[5];</p>
New cards
28

Initializing an array

An array can be preset values to it, however, the syntax is a little different. Everything will be the same except after declaring the size you will use curly brackets {}, and write the values you want inside dividing it using commas.

<p>An array can be preset values to it, however, the syntax is a little different. Everything will be the same except after declaring the size you will use curly brackets {}, and write the values you want inside dividing it using commas.</p>
New cards
29

Accessing elements within an array

Write the name of the array and surround the index/element with square brackets.

<p>Write the name of the array and surround the index/element with square brackets.</p>
New cards
30

Changing a value in an array

Access the element you want and treat it as a variable

<p>Access the element you want and treat it as a variable</p>
New cards
31

Length of an Array

Syntax is very similar to a string, thus being:

array.length;

  • Only difference is the array doesn’t have brackets at the end while strings do

New cards
32

Index Errors

Just like strings, you cannot ask for an element/index that does not exist. There will be an error telling you that element does not exist.

  • ArrayIndexOutofBounds Exceptions

New cards
33

Method Set Up

Access Levels:

  • Public

  • Private

Return Type:

  • Void

  • Data Types

Address:

  • Method name

Parameters:

  • The variables you want in the method

<p><strong>Access Levels:</strong></p><ul><li><p>Public</p></li><li><p>Private</p></li></ul><p><strong>Return Type:</strong></p><ul><li><p>Void</p></li><li><p>Data Types</p></li></ul><p><strong>Address:</strong></p><ul><li><p>Method name</p></li></ul><p><strong>Parameters:</strong></p><ul><li><p>The variables you want in the method</p></li></ul>
New cards
34

Void Method

Does not return values back to the main method, so whatever is in the method stays in the method.

  • Key word return is not needed

New cards
35

Passing data into methods

When initializing the method you only have to write the name of the variable in the brackets. However within the parameters of the method, the variable’s data type must line up with the ones on the initializer.

  • Order matters

<p>When initializing the <strong>method </strong>you only have to write the name of the variable in the brackets. However within the parameters of the method, the variable’s data type must line up with the ones on the initializer. </p><ul><li><p><strong>Order matters</strong></p></li></ul>
New cards
36

Data within a method

The passed data is not the same as the data in main. Although in some cases the variable name is the same, they are not the same variable. Meaning whatever changes are made within the method, will only affect the variable in it and not main.

New cards
37

Return in Method

This is used when we want to return a value back into main using method.

  • The data type you are returning must match the return type in the method header

New cards
38

Arrays in Method

When passing arrays into methods this is known as a PASS-BY REFERENCE. This is because an array is an object that has a memory location/memory address.

  • Changes made to the array in a method will also be changed in main since both point to the same memory location

New cards
39

Pass By Value VS Pass By Reference

Pass By Value: when a variable is assigned to another variable, the value stored in the variable is copied into the new variable.

Pass By Reference: Passing objects to a method.

New cards
robot