Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Knowledge base

Knowledge base

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 5788

Java

Checking, adding, and removing set elements in Java

Check whether an element belongs to a set and tell whether an addition or removal changed it. Use `LinkedHashSet` to track completed lessons without duplicates and in insertion order.

Intermediate · Java SE 21
Java

The + operator: addition and string concatenation

In Java, + adds numbers or concatenates text when at least one operand has type String. Operand types, numeric promotion, and parentheses determine the result. Unary + preserves the value after type promotion.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Addition assignment (+=)

The += operator adds a value to a variable or appends text to a String and stores the result, including an implicit conversion to the variable's type.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Array element access: array[index]

The expression array[index] selects an array element for reading or writing. Indices start at zero, and Java checks their bounds at run time.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Assignment operator (=)

The `=` operator stores a value in a variable; it does not test equality. It requires compatible types, and the assignment expression itself also produces a value, allowing assignments to be chained.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise AND operator (&)

The & operator preserves bits that are 1 in both integral operands. Use it to mask values and test flags. With boolean values, it means AND without short-circuit evaluation.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise AND assignment operator (&=)

The &= operator stores an AND result in its left operand: bitwise for integral values, logical for boolean values.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise complement operator ~

The unary ~ operator flips every bit of an integral value after numeric promotion. Its result has type int or long. It is not the logical complement operator !: ~ does not accept boolean values.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise OR operator (|)

The | operator combines corresponding integer bits: a result bit is 1 when at least one input bit is 1. With boolean operands, it performs logical OR without short-circuiting.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise OR assignment (|=)

The |= operator combines a variable’s value with the right operand using OR and stores the result. It supports integral and boolean values.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Bitwise XOR operator (^)

The ^ operator applies XOR to corresponding bits of integral values. For boolean values, it tests whether they differ.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

XOR assignment operator (^=)

The ^= operator stores an XOR result in its left operand. It works with integral types and boolean; it does not mean exponentiation.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Type cast: (type)

The (type) operator explicitly converts a value to a specified type. Numeric casts can lose data, and reference casts can throw ClassCastException; they do not change an object's class.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Conditional operator ?:

The ?: operator selects one of two values based on a condition. It is an expression with three operands; only the selected branch is evaluated at run time.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Decrement operator --

The -- operator subtracts 1 and stores the result in a variable. The x-- form yields the previous value, whereas --x yields the new value. Both forms update the variable while evaluating the expression.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Division operator /

The / operator computes a quotient. Operand types determine whether division is integer or floating-point, affecting fractional results and the behavior of division by zero.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Division assignment operator /=

The /= operator divides a variable’s saved value by the right operand and stores the result back, with an implicit conversion to the variable’s type.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Equality operator ==

The == operator returns boolean: it compares primitive values or reference identity. For String objects it does not compare contents; use equals for that.

Basic · Java SE 21; repository runtime, production runtime not attested
Java

Greater-than-or-equal operator (>=)

The >= operator compares numeric values and returns boolean. It includes equality, making it useful for checking thresholds that include the boundary value.

Basic · Java SE 21; repository runtime, production runtime not attested