JAVA
Copying 2d Arrays using arraycopy()
To make the above code more simpler, we can replace the inner loop with System.arraycopy() as in the case of a single-dimensional array. For example,
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int[][] source = {
{1, 2, 3, 4},
{5, 6},
{0, 2, 42, -4, 5}
};
int[][] destination = new int[source.length][];
for (int i = 0; i < source.length; ++i) {
// allocating space for each row of destination array
destination[i] = new int[source[i].length];
System.arraycopy(source[i], 0, destination[i], 0, destination[i].length);
}
// displaying destination array
System.out.println(Arrays.deepToString(destination));
}
}
Output:
[[1, 2, 3, 4], [5, 6], [0, 2, 42, -4, 5]]
Here, we can see that we get the same output by replacing the inner for loop with the arraycopy() method.
SQL
INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.
It is possible to write the INSERT INTO statement in two ways:
Syntax 1
Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Syntax 2
If you insert values for ALL the columns of the table, you can omit the column names.
However, the order of the values must be in the same order as the columns in the table:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
INSERT INTO Example
Here we insert values for ALL the columns of the table, so we omit the column names.
The following SQL inserts a new record in the "Customers" table:
Example
INSERT INTO Customers
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
References :
https://www.programiz.com/java-programming/copy-arrays
https://www.w3schools.com/sql/sql_insert.asp
Top comments (0)