Java Data Types ArrayList
byte/short/int/long ArrayList<Double> nums = new ArrayList<>();
2^ (8/ 16/ 32/ 64) nums.add(2.3); nums.size() == 1double a = nums.get(0);
float [32bit] / double [64bit]
1.0f / 1.0d, 1.0 String Functions
char [16bit] s.equals(String s2) -> bool
"U", "±" s.toLowerCase()
String "Hello World" s.toUpperCase()
s.replace(char old, char new)
Inc- / Decrement s.replace(String old, String new)
a++ s.indexOf(String s) //-1 if not availabe
++a s.lastIndexOf(String s)
Exception Handling
a--
try { statements; }
--a Java Statements
catch (ExceptionType e1) { sta
➜ return a++ / a-- ➜ return a If Statementif ( expression ) {
statements tements; }
Variables } else if ( expression ) { catch (Exception e2) { catch-all
statements statements; }
int i = 5, j;
} else { finally { statements; }
int a = 3, b = a + 1;
statements
final int c; //=> Constant
}
c = 22; // may be init after
Encapsulation
While Loopwhile ( expression ) {
Bitwise Shifts statements
Bundling of data and operations to
~ Complement } be performed on that data into
<< Shift left single unit is called as
>> Shift right Do-While Loopdo { encapsulation.
>>> Shift right Zero fill statements ✓ Encapsulation in Java can be
} while ( expression ); achieved by including both
variables (data) and methods
Naming Convention For Loopfor ( int i = 0; i < max; ++i) { (operations) which act upon those
Constants: statements
variables into a single unit called
MAX, PI, MIN_TIME }
class
Variables, Methods, Packages:
xVal, int1Arr, date, showDate
Classes:
Abstract / Interface
Date, DatabaseHelper
abstract Method
public abstract fun();
Array abstract Class
int[] a; //Declaration public abstract class Test{}
a = new int[5] //Dimensionint[] a = new Interface
int[5]; Like abstract class, but with only
int[] b = {10, 20, 30}; abstract functions. You don't need
int[][] matrix = new int[2][3]; abstract for these
Abstract Classes and Methods are
Array Methods without implementation.
int[] a; You use implements for Interfaces
a.length; //length of array
Connect with me:
LinkedIn | YouTube | TopMate | Medium
Japneet Sachdeva
Map Methods List Methods
add(index, value) inserts given value
containsKey(key) true if the map at given index, shifting subsequent
contains a mapping for the given key values right
get(key) the value mapped to the given indexOf(value) returns first index
key (null if none) where given value is found in list (-1 if
keySet() returns a Set of all keys in the not found)
map get(index) returns the value at given
put(key, value) adds a mapping from index
the given key to the given value lastIndexOf(value) returns last index
putAll(map) adds all key/value pairs where given value is found in list (-1 if
from the given map to this map not found)
remove(key) removes any existing remove(index) removes/returns value
mapping for the given key at given index, shifting subsequent
values left
Methods Found in both Lists and set(index, value) replaces value at
Sets (ArrayList, LinkedList, given index with given value
HashSet, TreeSet) Stack Methods
peek() returns the top value from the
add(value) adds value to collection stack without removing it
(appends at end of list) pop() removes the top value from the
contains(value) returns true if the stack and returns it; peek/pop throw an
given value is found somewhere in this EmptyStackException if the stack is
collection empty
remove(value) finds and removes the push(value) places the given value on
given value from this collection top of the stack
removeAll(collection) removes any Inheritance
elements found in the given collection Inheritance, as name itself suggests, is
from this one used to inherit properties from parent
retainAll(collection) removes any class to child class.
elements not found in the given Using inheritance, you can reuse
collection from this one existing tried and tested code.
Methods Found in ALL collections Abstraction
Abstraction means separating ideas
(Lists, Stacks, Queues, Sets, Maps) from their actual implementations.
clear() removes all elements of the
Using abstraction, you define only ideas
collection
in one class so that those ideas can be
equals(collection) returns true if the
implemented by its subclasses
given other collection contains the
according to their requirements.
same elements
isEmpty() returns true if the collection
has no elements
PolyMorphism
✓ Poly means many and morphs means
size() returns the number of elements
forms. So, anything which has multiple
in the collection
forms is called as polymorphism
toString() returns a string
representation such as "[10, -2, 43]"
Connect with me:
LinkedIn | YouTube | TopMate | Medium
Japneet Sachdeva