Data & Data Types

Important things to know

Constants

final int someConstant = 10;

Data Types

Data types in Java
  • These are Java's primitive datatypes

  • you can use + operator on datatypes smaller than int otherwise anything that gets promoted to Integer.

  • To get max and min value of data type :

Strings

Important functions

  • equalsIgnoreCase

  • toLowerCase

  • To check Strings in Java don't use "==" instead use :

    • str1.equals(str2)

  • charAt(0)

  • String.contains()

  • s.indexOf('i')

  • split(";")

  • join()

  • toString() Dont use with strings

  • String is a final and immutable class

  • To create a mutable string in java, Java has two classes

    • StringBuffer and

    • StringBuilder

String Builder

Formatter

String Joiner

String Tokenizer

Strings on Heap & Pool

  • created on heap, even literals

Difference between string on heap and Pool

Strings on Heap vs Pool

String intern()

Big Decimal

imports :

Big Decimal objects are immutable

Creating Big Decimals

Comparing

Operations

String.Format

Best Practises

Big Integer

Initialisation

  • To convert long or int values to Big Integer use:

  • To convert a numeric String to Big Integer use:

  • There are predefined constants for common values:

  • BigInteger.ZERO — value of "0".

  • BigInteger.ONE — value of "1".

  • BigInteger.TEN — value of "10".

Operations

Comparing

In general, do not use use the == operator to compare Big Integers

  • == operator: compares references; i.e. whether two values refer to the same object

  • equals() method: compares the content of two Big Integers.

Last updated

Was this helpful?