Arrays class and it’s methods.

Fatima Yousif
Nov 1 · 2 min read
source: adrianmejia.com

Every week discloses a new topic concerned with the subject “Data Structure Algorithm”. So in this week’s discussion I will be having Arrays as the “old school” way of dealing with storing data and structuring it. Let’s get straight into it.

Arrays?

Array stores elements with the same variable name and under same type. Arrays are to be worked with static functionality that is the size of the array remains constant throughout the whole program.Arrays can either be single dimensional or 1D arrays or multidimensional arrays (2D,3D, etc).

All the abstract data types as of the stacks, queues, deque (double-ended queue), maps, lists can have arrays that are used in their functionalities like for the stack we have some methods to work on: PUSH, POP, PEEK, ISEMPTY, SIZE and etc. So to implement such methods the use of static arrays was used back then. Same is the case for the implementation of other abstract data types mentioned.

Arrays can have the values directly initialized, or are stored through for loop(s) with the input numbers or with the random numbers. Arrays for instance can be retrieved or displayed back through either for loop or for each (the limitations are that it can be used only with arrays).

ARRAYS CLASS:

Arrays is a class in the util package of java such that it provides various static methods for us as mentioned below:
1) fill: fills one array with the value passed as argument.
SYNTAX: Arrays.fill (int[], int value);

2) sort: sorts the array passed in arguments.
SYNTAX: Arrays.sort (int[]);

3) binarySearch: searches for the particular element in the SORTED array with the binary search algorithm.

SYNTAX: Arrays.binarySearch (int[],int target);

4) copyOf: copies an array with an argument telling the number of elements to be copied.
SYNTAX: Arrays.copyOf (source_arr[],int no_of_elements_to_be_copied);

5) copyOfRange: copies an array from a particular element till a particular element. The copied elements can be later stored in an array.

SYNTAX: Arrays.copyOfRange (int[], int from, int till);

On that note, we ended the Arrays’ class static methods usage. With the addition of multidimensional arrays as the next heading.

MULTIDIMENSIONAL ARRAYS:

“The array of array” can be simply called a multidimensional array. Multidimensional arrays can be 2,3 or more dimensional, With the increment of square brackets for each in the initialization syntax. They can be used for the various mathematical problems including matrix operations.
Practice the above array methods as they save time and make ease, and think about the implementation of them, so as to be more functional and thoughtful.

Looking forward to some new topics in town for the next week. Stay tuned.

    Fatima Yousif

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade