JAVA
class Main {
public static void main(String[] args) {
int [] numbers = {1, 2, 3, 4, 5, 6};
int [] positiveNumbers = numbers; // copying arrays
// change value of first array
numbers[0] = -1;
// printing the second array
for (int number: positiveNumbers) {
System.out.print(number + ", ");
}
}
}
Explanations
-
class Main {: Declares a public class namedMainto serve as the structural framework for the application. -
public static void main(String[] args) {: The entry point method where the Java Virtual Machine begins execution. -
int [] numbers = {1, 2, 3, 4, 5, 6};: Declares and initializes an integer array namednumberscontaining six elements in memory. -
int [] positiveNumbers = numbers;: Copies the reference (memory address) of thenumbersarray into a new array reference variable namedpositiveNumbers. This does not duplicate the underlying array data; both variables now point to the exact same array object in memory. -
numbers[0] = -1;: Modifies the first element (index0) of the array to-1. Because bothnumbersandpositiveNumberspoint to the same array object, this change will also be reflected when accessing the array throughpositiveNumbers. -
for (int number: positiveNumbers) {: Starts an enhanced for-loop to iterate through each element stored in thepositiveNumbersarray reference. -
System.out.print(number + ", ");: Prints each element of the array followed by a comma and a space on the same line (resulting in output where the first item is-1instead of1). -
}: Closes the loop block. -
}: Closes themainmethod block. -
}: Closes theMainclass block.
SQL
IN Operator
The IN operator is used in the WHERE clause to check if a specified column's value matches any value within a provided list.
The IN operator functions as a shorthand for multiple OR conditions, making queries shorter and more readable.
Syntax :
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
Reference :
https://www.w3schools.com/sql/sql_in.asp
https://www.programiz.com/java-programming/copy-arrays
Top comments (0)