DEV Community

Cover image for One Commit at a Time ! Series - 11
Annapoorani Kadhiravan
Annapoorani Kadhiravan

Posted on

One Commit at a Time ! Series - 11

JAVA

Copying Arrays Using copyOfRange() method
We can also use the copyOfRange() method defined in Java Arrays class to copy arrays. For example,

// To use toString() and copyOfRange() method
import java.util.Arrays;

class ArraysCopy {
    public static void main(String[] args) {

        int[] source = {2, 3, 12, 4, 12, -2};

        // copying entire source array to destination
        int[] destination1 = Arrays.copyOfRange(source, 0, source.length);      
        System.out.println("destination1 = " + Arrays.toString(destination1)); 

        // copying from index 2 to 5 (5 is not included) 
        int[] destination2 = Arrays.copyOfRange(source, 2, 5); 
        System.out.println("destination2 = " + Arrays.toString(destination2));   
    }
}
Enter fullscreen mode Exit fullscreen mode

Output

destination1 = [2, 3, 12, 4, 12, -2]
destination2 = [12, 4, 12]

int[] destination1 = Arrays.copyOfRange(source, 0, source.length);
Here, we can see that we are creating the destination1 array and copying the source array to it at the same time. We are not creating the destination1 array before calling the copyOfRange() method.


SQL

SQL Aliases
An alias is created with the AS keyword, and is often used to make a column name more readable.

An alias only exists for the duration of that query.

Alias for Columns
The following SQL creates two aliases, one for the CustomerID column and one for the CustomerName column:

SELECT CustomerID AS ID, CustomerName AS Customer
FROM Customers;
Enter fullscreen mode Exit fullscreen mode

Syntax
Alias for column:

SELECT column_name AS alias_name
FROM table_name;

Alias for table:

SELECT column_name(s)
FROM table_name AS alias_name;


References :

https://www.programiz.com/java-programming/copy-arrays
https://www.w3schools.com/sql/sql_alias.asp

Top comments (0)