This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

takeaway

I believe that many beginners programming partners have a choice of language phobia, for Java also do not know how to learn, this article J elder brother will give you the most suitable for small white learning JavaEE tutorial.

Overview of big data

# Big data and cloud computing learningConcept: Massive data, a collection of data with a high rate of growth, diversity of data types, and a period of time that cannot be captured, managed, and processed using conventional software. Features :4V features (generally accepted) a large variety of high-speed values# What can Big Data do?In the mass of various types of low value density data, we need to carry out: data collection, data storage, data cleaning, data analysis, data visualization. This process is what big data is all about.# Use languageJAVA8 stable (up to date14Write Once Run Anywhere JDK development environment JRE running environment JVM VIRTUAL machineCopy the code

Java based

Java data type classification

// Basic data typeInteger - byte:byte- Short integer:short- integer:int- Long integer type:longFloating point - Single precision floating point:float- Double precision floating point type:doubleCharacter:charBoolean:boolean
// Reference the data type
Copy the code

identifier

// An identifier is an ordered sequence of several characters. Rules to follow in identifiers:
1.Consists of alphanumeric underscores and $2.You can't start with a number3.Cannot have the same name as system keyword or reserved word// The name of the hump.
1.Looking at text meaning2.Hump nomenclature (large hump nomenclature, small hump nomenclature) - capitalize the first letter - except the first word - small hump nomenclature is used by default without special instructionsCopy the code

Variable/constant

The value of a variable (age, weight) can be changed and the value of a variable (a person’s date of birth) can not be changed and the value is called a constant (a person’s date of birth)

Type conversion

// Cast
// Automatic type conversion
// Special instructions:
	1.byte short charType data is automatically converted tointtype2.Floating-point conversions discard everything after the decimal point except the integer partCopy the code

Common operator

// count + - * / % ++ --The ++ increment operator after a variable indicates that the value is evaluated before the increment is performed1The operation before the variable is added first1The operator after the value -- the decrement operator is the same as ++ + and -- has the highest priority// Assignment operator =Combinatorial operators can be combined with other operators. Combinatorial operators implicitly contain type conversions// Relational operator > >= = < <= ==! =
    // 1. The result of the relational operator must be of type Boolean
    // 2
/ / logical operators & |! ^ && | | to the operation of two Boolean valuesJava Python go javascript c & and && && && and: Logical and, two true is true, either is false, the result is falsefalse| or | | | | | | or: logic or two false is false, any one is true, the result is truetrue! The not! ! ! Not: logical not, not true is false, not false is true. ^ Xor: logical xor, same is false, different is true. && short circuit and, if the previous results can determine the overall operation, don't participate in the back of the expression | | short circuit or, if the previous results can determine the overall operation, at the back of the expression is not involved in operations in the javascript logic operator depends on the right, the right why the value returned is why// bit operatorOnly in two integer operations & a and operations, to complement with each operation | or operation, or operation of the complement each ^ an exclusive or operation, Xor operation on each bit of the complement ~ bitwise inverse operation including sign bit << left-shift operation >> right-shift operation highest complement sign bit >> unsigned right-shift operation left complement0That is, the highest bit complement is not the sign bit but0symbol64 32 16     8421
0   (0  0   0)   (0000) --> source code directly write complement: example: -45 = 32 + 8 + 4 + 1
    1010 1101The source code1101 0010 + 1 = 1101 0011If you move the complement two to the right, you don't want the overflow1111 0100 11  --> 11The complement after the move:1111 0100Reverse bit source code again:1000 1011 + 1 = 1000 1100The final result is minus12In the right shift operation, every image moved one bit to the right is equivalent to removing one2, but here follow the round down11.25 = 12Interview question: How to calculate efficiently2*8
    2*82+ 8 times8*28+8
    2<<3This is the most efficient// The ternary operatorExpressions: Boolean result expressions/Boolean variables? value1Value:2If I say hello, the Boolean before it istrue, the overall result is value1. Otherwise the whole result is value2.// The priority of the operatorUnary operator (can only operate on one data :+ - ++ --! ~)> binary operator (can operate on two data :+ - * /)> ternary operator (ternary operator? The assignment operator has the lowest precedence. The arithmetic operator: multiply/divide module > add/subtract logic operator: and > or, xor parentheses have the highest precedenceCopy the code

Process control

// Process control classificationSequential structure/branch structure/loop Structure - Java sequential structure/branch structure/loop structure -C sequential structure: code is executed from top to bottom, line by line. Is the default structure for program execution branch structure: a program encounters multiple possibilities at a particular node and, depending on the condition, chooses a branch to continue the loop structure: a piece of code needs to be repeated multiple times.// Branch flow control -if/switch
            // If else
if (condition) {  // condition condition (Boolean)
    // code segment 1
}
else{
    // Code segment 2
}
		// The second type if - else if
if(){
    
}else if(){
    
}...
else{}// switch
switch(variable) {case1{
        // branch statement 1
    }
    case2{
        // branch statement 2
    }...
    default:}/ / instance
int season = 1;
switch (season) {
    case 1:
        System.out.println("Spring");
        break;
    case 2:
        System.out.println("Summer");
        break;
    case 3:
        System.out.println("Autumn");
        break;
    case 4:
        System.out.println("Winter");
        break;
    default:
        System.out.println("The wrong season");
}
switchPenetrability: refers to whenswitchAnd a certain number of variablescaseValues are matched, and subsequent values are skippedcaseordefaultThe match is straight back through. To prevent penetration, you can use keywordsbreak;
// Loop process control -for/while
for(the starting point of the cycle, the condition of the cycle, the step of the cycle){// This code will be repeated when the loop condition is true
    // This is called a circular body} Loop start: a variable that will only be executed once. This is usually used to define a variable used to control the loop. Loop condition: an expression for a Boolean result that, when true, executes the loop body// while
while(cyclic condition){/ / the loop body
}

// do-while
do {
    / / the loop body
} while(cyclic condition); If none of the conditions are true from the beginning, thendo-whilethanwhileThe loop executes logic one more time// Two keywords
	breakEnd the loop immediately, regardless of whether the loop condition is truecontinueStop this cycle immediately and enter the next cycle immediately if the number of cycles is predictable recommendedforLoops Are recommended if the number of loops is unexpected, but there is a clear end conditionwhilecycle// Loop labels
OUTER: // Close the outer loop with the inner loop
for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
        if (j == 3) {
            break OUTER;
        }
        System.out.println("i = "+ i + ", j = "+ j); }}Copy the code

Loop case

// Print the sum of all odd numbers from 0 to 100
int sum = 0;
for (int number = 1; number <= 100; number++) {
    if (number % 2! =0) {
        // System.out.println(number);
        sum += number;
    }
}
System.out.println(sum);
// Print the multiplication table
int line = 1;
for (; line <= 9; line++) {
    for (int column = 1; column <= line; column++) {
        System.out.print(column + "x" + line + "=" +column*line + "");  Println has a newline character
    } Print (end="")
    System.out.println();
} 
// White chicken with 100 coins
// We know that each hen is 5 yuan, each cock is 3 yuan, and three chickens are 1 yuan
// I have 100 yuan to buy chickens, and I want to buy 100 chickens
// Output all purchase options
for (int m = 0; m <= 100 / 5; m++) {
    for (int g = 0; g < 100 / 3; g++) {
        for (int x = 0; x <= 100; x += 3) {
            // The number of chickens is a multiple of three
            if (m * 5 + g * 3 + x / 3= =100 && m + g + x == 100) {
                System.out.println("For sale: hens" + m + "R" + g + "Chicken"+ x); }}}}Copy the code

methods

// The concept of methodsWe wrap up logic that needs to be executed multiple times and call it when needed. Methods exist for the purpose of events (making them repeatable, reducing code redundancy, and improving code reuse and maintainability)// Method definition and invocation[Access modifier][Other modifiers] Return value type Method name ([parameter list]){method body}public class FirstMethod {
    public static void main(String[] args) {
        // Access modifier: access modifier
        // Other modifiers: static
        // Return value type: void
        // Method name: small hump name
        // Write the argument list in parentheses
        print();  // Call the method
    }

    public static void print(a) {  // If the logic in this method needs to be executed, the method needs to be called
        / / the method body
        System.out.println("This is my first method"); Methods are defined inside the class, alongside the main function (methods are not allowed) access modifier// Method parametersWhen a method is called, the data passed in is called a parameter (defined in parentheses) parameter: the parameter defined when the method is defined Argument: the value to be passed Parameter: the argument assigns a value to the parameter --> Pass the parameter// Return value of the methodWhen a function is called, in some cases the result is not returned; In other cases there must be a return valuereturnKey words: the result of method execution; End of method.public class ReturnType {
    public static void main(String[] args) {
        System.out.println("And:" + add(1.2));
    }

    public static int add(int num1, int num2) {  // int Return value type
        returnnum1 + num2; }}// Method overloadIf multiple methods in a class meet one of the following conditions, the relationship between them is overloaded · method name is the same · parameter is different ~ parameter is different, reflected in the number of parameters or the type of parameters (method entry is different) note: method overload does not matter the return value!public class Overload {
    public static void main(String[] args) {
        add();
        add(2);
        add(3.4);
        add("aa");
    }

    public static void add(a) {
        System.out.println("No parameters");
    }

    public static void add(int num1) {
        System.out.println("add(int)");
    }

    public static void add(int num1, int num2) {
        System.out.println("add(int int)");
    }

    public static void add(String s) {
        System.out.println("add(String)"); }}// Method recursionRecursion is an idea of programming. When solving a problem, you can break it down into smaller pieces. By solving these small problems, we can gradually solve the big problem.package com.laity.basicSyntax.method;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.method
 * @dateDate: November 12, 2021 23:36 *@Description: method recursion */
public class Method2 {
    public static void main(String[] args) {
        // multiply(9);
        System.out.println(multiply(10));
        System.out.println(sum(100));
    }

    /** * /** Press CTRL + Enter * to compute the factorial of a number **@paramNum Is the number * that needs to be factored@returnThe calculated result is */
    public static int multiply(int num) {
        // Set exit conditions
        if (num == 1) {
            return 1;
        }
        // progression and regression (call yourself)
        return num * multiply(num - 1);
    }

    public static int sum(int n) {
        if (n == 1) {
            return 1;
        }
        return n + sum(n - 1); }}Copy the code

An array of

// Concept: a group of contiguous storage Spaces that store multiple values of the same data type (a data container)Features: Same type, fixed length.// Array declaration (note: whenever you see the keyword new, you create space on the heap)
int [] array = new int[5];  // int[5] specifies the size of the arrayThe default values for the data in the array are: integer:0Floating point:0.0Character:'\u0000'Boolean:falseReference data types:null
    
public class Array1 {
    public static void main(String[] args) {
        // Preamble: Use [] to represent an array, and write the data types that can be stored in the array before the brackets
        1. Declare an array
        // 2. Array instantiation: Allocate memory space for the array and allocate the initial value of the array
        // new: To make space for the array, use the keyword new
        // Specify the length of the array while instantiating
        // The default value of the data in the array is:
        int[] array = new int[5];  // int[5] indicates that the storage capacity is 5
        // Specify the data stored in the array while instantiating the array
        // By default, the array stores 5 data, which means the array is 5 in length
        int[] array2 = new int[] {1.2.3.4.5};
        // omit new int[]
        int[] array3 = {1.2.3.4.5}; }}// Access the elements in the array
public class Array2 {
    public static void main(String[] args) {
        1. Instantiate an array
        int[] array = {1.2.3.4.5};
        // 2. There are two operations: read and write
        int a = array[2];
        System.out.println(a);
        / / 3.. Modify an element in an array
        array[3] = 100;
        System.out.println(array[3]); }}// Array traversalYou get each element in the array in the order in which it's stored.package com.laity.basicSyntax.day1.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day1.bArray
 * @dateDate: November 13, 2021 9:54 *@Description: array traversal */
public class Array3 {
    public static void main(String[] args) {
        int[] array = {1.2.3.4.5.6.7.8.9.10};
        for (int i = 0; i <= 9; i++) {
            System.out.println(array[i]);
        }
        for (int j = 0; j < array.length; j++){
            System.out.println(array[j]);
        }
        // Only idea supports array.fori 100.fori

        // Enhance the for loop
        // I use each element of the array in turn to assign the iterated variable
        for (intelement : array){ System.out.println(element); }}}// Note: This enhanced for loop is the same as Python: for I in array:print(I)

// A reference in an array
public static void main(String[] args) {
    int[] array = {10.20};
    swap(array);
    System.out.println(array[0]);
    System.out.println(array[1]);
}

public static void swap(int[] arr) {
    int temp = arr[0];
    arr[0] = arr[1];
    arr[1] = temp;
}
// Sort the arrayTo reorder the elements of an array by size. Selection sort: a fixed value is in order of size with other values, swapping places. Bubble sort: Two adjacent values compare sizes and swap positions. JDK sort(java.util.arrays.sort)The JDK provides sorted in Python by default with ascending sort (from smallest to largest)Arrays.sort(array); Sequential query Binary queryCopy the code

Selection sort

// Select sort: fixed values are compared with other values in order of size, switching positions.
package com.laity.basicSyntax.day1.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day1.bArray
 * @dateDate: November 13, 2021 13:44 *@Description: Select sort */
public class ArraySort5 {
    public static void main(String[] args) {
        int[] array = {10.5.6.3.9.2.4};
        int[] arrays = {10.5.6.3.9.2.4.0.1.4.7.8};
        sort1(array);
        sort2(arrays);
        for (int i : array) {
            System.out.print(i + ",");
        }
        System.out.println();
        for (int i : arrays) {
            System.out.print(i + ","); }}/** * Sort the array in ascending order (from smallest to largest) using a selection sort **@param array
     */
    public static void sort1(int[] array) {
        // Select sort
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    // Swap elements
                    inttemp = array[i]; array[i] = array[j]; array[j] = temp; }}}}public static void sort2(int[] array) {
        // Full version selection sort
        // Used to control how many comparisons occur
        for (int i = 0; i < array.length - 1; i++) {
            // Declare a variable to record the minimum index of the remaining elements
            int min = i;
            // Compare each successive element with the current minimum to find the new minimum
            for (int j = i + 1; j < array.length; j++) {
                // Compare the JTH element with the lowest recorded value
                if (array[min] > array[j]) {
                    // Update the minimum subscriptmin = j; }}// Swap the I and min bits
            if(i ! = min) {inttemp = array[i]; array[i] = array[min]; array[min] = temp; }}}}Copy the code

Bubble sort

// Bubble sort: two adjacent values compare sizes and swap positions.
package com.laity.basicSyntax.day1.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day1.bArray
 * @dateDate: November 13, 2021 16:46 *@Description: Bubble sort */
public class ArraySort6 {
    public static void main(String[] args) {
        // instantiate an array
        int[] array = {1.3.7.2.9.4.8.0.6.5};
        // Sort the array
        sort1(array);
        // Loop print
        for (int i : array) {
            System.out.print(i + ","); }}/** * Use bubble sort to sort an array in ascending order ** The core idea of bubble sort is to compare two adjacent elements starting at the 0th bit in each comparison, and swap ** when the swap condition is satisfied@param array
     */
    public static void sort1(int[] array) {
        // How many times does the loop comparison take place
        for (int i = 0; i < array.length - 1; i++) {
            // Control how many times the comparison takes place for each trip
            // j < array.length - 1 - i
            for (int j = 0; j < array.length - 1 - i; j++) {
                // Compare two adjacent elements in turn
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }
}
Copy the code

Order query

package com.laity.basicSyntax.day1.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day1.bArray
 * @dateDate: November 13, 2021 16:59 *@Description: Sequential query */
public class FindElement7 {
    public static void main(String[] args) {
        int[] array = {1.3.5.6.9.7.2.0.10};
        int index = indexOf(array, 50);
        System.out.println(index);   // return index
    }

    /** * Uses a sequential query to query the occurrence of the subscript ** for the specified element in the array@paramArray Specifies the array to query@paramElement Specifies the element to be queried@returnThe following table where the element appears; If the element does not exist, -1 is returned; * /
    public static int indexOf(int[] array, int element) {
        // Iterate over each element in the array
        for (int i = 0; i < array.length; i++) {
            // Compare each element in turn with the element to be queried
            if (array[i] == element) {
                // If the comparison passes, the index is the index of the element to be queried
                returni; }}// If the loop is complete and no result is returned, the element does not exist
        // If the element does not exist, we return -1
        return -1;
    }
Copy the code

Binary query

// Divide an array into two subtables using the middle position of the array. If the key recorded in the middle position is greater than the lookup key, the former child table is further searched, otherwise the latter child table is further searched. Repeat the above process until you find a record that meets the criteria, so that the search succeeds, or until the child table does not exist, at which point the search fails.
// Binary query, the array must be sorted, otherwise the binary query cannot be used. (That is, sorted: ascending or descending)

package com.laity.basicSyntax.day2.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day2.bArray
 * @dateDate: November 14, 2021 11:34 *@Description: binary query */
public class BinarySearch {
    public static void main(String[] args) {
        int[] array = {1.4.6.7.8.10.12.13};
        int index = binarySearch(array, 10);
        System.out.println(index);
    }

    /** * From an array, use binary query to query the subscript ** of the elements@paramArray Array to be queried *@paramElement Specifies the element to be queried@returnThe subscript * /
    public static int binarySearch(int[] array, int element) {
        // Define two variables to record the upper and lower limits of the range respectively
        int min = 0, max = array.length - 1;

        while (max >= min) {
            // find the middle subscript
            int mid = (max + min) / 2;
            // Determine the size relationship between the middle element and the element to be queried
            if (array[mid] == element) {
                return mid;
            } else if (array[mid] > element) {  / / check on the left
                // Modify the range of the upper limit
                max = mid - 1;
            } else {
                // Change the lower limit of the range
                min = mid + 1; }}// If no result is returned at the end of the loop, the query does not exist in the array
        return -1; }}Copy the code

Variable length parameter

// Concept: Can accept multiple parameters of the same type, no limit on the number of parameters, use the same method as array.
// When calling a method, the number of arguments can be as many as you want. It's essentially an array
// Syntax: data type... Parameter name (must be placed last in the parameter list, and there can be only one parameter)

package com.laity.basicSyntax.day2.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day2.bArray
 * @dateDate: November 14, 2021 12:13 *@Description: variable length argument list */
public class MutipleParameter {
    public static void main(String[] args) {
        int[] array = {1.2.3.4.5.6.7.8.9.10};
        int Max = getMax(array);
        System.out.println("Maximum value :" + Max);
        int Min = getMin(1.2.3.4.5.6.7.8.9.10);  // You can write it like this
        System.out.println("Minimum :" + Min);
    }

    public static int getMax(int[] array) {
        int max = array[0];
        for (int element : array) {
            if(element > max) { max = element; }}return max;
    }

    public static int getMin(int. arrays) {  // int... The writing method of unequal length parameter of arrays
        int min = arrays[0];
        for (int element : arrays) {
            if(element < min) { min = element; }}returnmin; }}Copy the code

2 d array

// int[][] array3 = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};

package com.laity.basicSyntax.day2.bArray;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day2.bArray
 * @dateDate: November 14, 2021 14:28 *@Description: a two-dimensional array */
public class Array2 {
    public static void main(String[] args) {
        // Access the elements of a two-dimensional array
        // 1. Instantiate a two-dimensional array
        int[][] array = new int[5] [3];
        // 2. Get a small array of arrays
        int[] arr = array[1];
        // 3. Modify the small array in the array
        array[1] = new int[] {2.3.4.5.6.7.8};
        System.out.println(array);
        // 4. Get the data in the small array
        int ele = array[1] [4];
        System.out.println(ele);
        // 5. Modify data in the small array
        array[2] [2] = 3;
        System.out.println(array);
    }

    public static void initArray(a) {
        // 1. Define and instantiate a two-dimensional array
        // int[][] array; // Declare a two-dimensional array in which each element is a small one-dimensional array

        1.1 Instantiate a two-dimensional array given the length of the array
        // The element stored in the two-dimensional array is NULL
        int[][] array1 = new int[5] [];for (int[] ints : array1) {
            System.out.println(ints);
        }
        // 1.2 Given the length of a two-dimensional array, and given the length of a one-dimensional array, instantiate
        // At this point, the one-dimensional array stored in the two-dimensional array has been instantiated
        // This is just the initial length. You can change it later
        int[][] array2 = new int[5] [3];
        System.out.println(array2);
        // 1.3 Instantiate the array with the specified value
        int[][] array3 = new int[] [] {{1.2.3}, {4.5.6}, {7.8.9}, {10.11.12}};
        System.out.println(array3);
        // 1.4 is the simplest
        int[][] array4 = {{1.2.3}, {4.5.6}, {7.8.9}, {10.11.12}}; System.out.println(array4); }}Copy the code

The Arrays tools

// There are several utility methods that operate on arrays
// Utility methods: convenient methods for manipulating arrays

package com.laity.basicSyntax.day2.bArray;

import java.util.Arrays;  / / package

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day2.bArray
 * @dateDate: November 14, 2021, 15:00 *@DescriptionThe: Arrays utility class contains several tools for manipulating Arrays */
public class ArrayTools {
    public static void main(String[] args) {
        // System.arraycopy();
        // Copy the element from the specified bit in an array to the specified bit in the target array. Copy the element of length
        // Note: do not overwrite the subscript
        // arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
        // Object SRC: original array
        // int srcPos: specifies the starting position of the original array bit
        // Object DST: destination array
        // int dstPos: specifies the starting position of the target array
        // int length: The number of elements copied is the length of the copy
        int[] src = {1.3.5.7.8.9.10};
        int[] dst = {20.30.40.50.60.70};
        System.arraycopy(src, 1, dst, 1.3);
        System.out.println(Arrays.toString(dst));
    }

    /** * Basic tools */
    public static void ArrayUsage(a) {
        // 1. Prepare an array
        int[] array = {1.3.5.7.8.9.10.17};
        int[] arr = {1.3.4.7.8.9.10.17};
        // 2.
        // If newLength exceeds the length of the original array, it can still be copied, but 0 is added to the final result
        int[] ret = Arrays.copyOf(array, 5);  // Copies a specified number of elements from the original array into a new array, and returns the new array

        // 2.1 Concatenates the elements of the array into a string
        String ret1 = Arrays.toString(ret);   // Concatenate a string to return
        System.out.println(ret1);

        // 2.2 Copies the elements of the specified range [from, to] from the original array into a new array and returns the new array
        // Form is not allowed to cross the boundary, otherwise an exception will be raised
        int[] ret3 = Arrays.copyOfRange(array, 2.7);
        System.out.println(Arrays.toString(ret3));

        // 2.3 Check whether two arrays are the same
        boolean equals = Arrays.equals(array, arr);  // This has the shortcut key.var
        System.out.println(equals);

        // 2.4 Populates the array with the specified data
        Arrays.fill(array, 8);  // Fill all elements of the array with 8
        System.out.println(Arrays.toString(array));

        // Sort the elements of an array (ascending sort)
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));  / / JDK sorting

        // 2.6 Use binary query to query the occurrence index of the specified element in the array
        int index = Arrays.binarySearch(array, 7); System.out.println(index); }}Copy the code

Array extensions

package com.laity.basicSyntax.day2.bArray;

import java.util.Arrays;

/ * * *@author : Laity
 * @Project: JavaLaity
 * @Package com.laity.basicSyntax.day2.bArray
 * @dateDate: November 14, 2021 23:45 *@Description: array of extended functions */
public class ArrayExtension {
    public static void main(String[] args) {
        // Array expansion: instantiate a new array of specified length, copy the elements of the original array into the new array

        int[] original = {1.4.7.8.9};
        // Requirement: Add a 0 to the end of an existing element
        // 1. Expand the original array by 1
        int[] newArray = new int[original.length + 1];
        // 2. Copy each element in Original into the new array in turn
        for (int i = 0; i < original.length; i++) {
            newArray[i] = original[i];
        }
        // 3. Put 0 in the last bit of newArray
        newArray[newArray.length - 1] = 0;
        // 4. Redirect original's address to
        original = newArray;
        // 5. Iterate through the array, printing all the elements in the array
        System.out.println(Arrays.toString(original));  // [1, 4, 7, 8, 9, 0]

        int[] array = add(original, 10);
        System.out.println(Arrays.toString(array));

        // array = remove(original, 3);
        array = newRemove(original, 3);
        System.out.println(Arrays.toString(array));
    }

    /** ** /
    public static void growup(a) {
        // The basic idea of array expansion

    }

    /** * You want to concatenate an element to the end of an existing array@paramArray An existing array *@paramElement The element to be concatenated@returnAdd elements to the array */
    public static int[] add(int[] array, int element) {
        // 1. Expand the original array by 1
        // 2. Copy each element in Original into the new array in turn
        array = Arrays.copyOf(array, array.length + 1);
        // 3. Place element last in newArray
        array[array.length - 1] = element;
        // 4. Return the concatenated array
        return array;
    }

    /** * Removes the element ** with the specified subscript from the array array@paramArray Array to be operated on *@paramElement The subscript * of the deleted element@returnReturns the array */ after the element has been deleted
    public static int[] remove(int[] array, int element) {
        if (element < 0 || element >= array.length) {
            return array;
        }
        // 1. Instantiate a new array with the length -1 of the original array
        int[] newArray = new int[array.length - 1];
        // 2. Copy the data of the first and second parts
        System.arraycopy(array, 0, newArray, 0, element);
        System.arraycopy(array, element + 1, newArray, element, array.length - 1 - element);
        // 3. Return the result
        return newArray;
    }

    public static int[] newRemove(int[] array, int element) {
        if (element < 0 || element >= array.length) {
            return array;
        }
        // Overwrite the elements after the element bit
        System.arraycopy(array, element + 1, array, element, array.length - 1 - element);
        // Return the result
        return Arrays.copyOf(array, array.length - 1); }}Copy the code

Arrays of stacks and stacks

int[] array = new int[5];
Copy the code

Shortcut key sorting

Main/PSVM, sout,... Ctrl+D copies the current row to the next row; Ctrl+Y deletes the line, but Ctrl+X is recommended; Ctrl+ALT+L formatting code; ALT+SHIFT+ point, ALT+SHIFT+ point; Move the current code up or down Ctrl+/, Ctrl+Shift+/ comment the code ALT+ Enter error fori for loop shortcut Crtl+ALT+T Select the code, hold down the shortcut key, The fifth is the code quickly in a loop The right mouse button | the Generate | getter and setter - > hold down shift click the need to members of the class Shortcuts FN + ALT + INSERT the right mouse button | getter/setter methods The Generate | Constructor - > hold down shift click the need to members of the class Shortcuts FN + ALT + INSERT a constructor What all don't choose the situation is to generate a no-parameter constructor with Ctrl + ALT + V. Var is inCopy the code