0% found this document useful (0 votes)
19 views7 pages

Group 2

Uploaded by

carmsecarms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Group 2

Uploaded by

carmsecarms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ARRAYS IN

JAVA
One-dimensional Arrays (1D Array)
- an array that holds a sequence of elements, all of the same type,
accessed through an index.
- the data stored in a continuous manner, which makes operations
like search, delete, insert much easier.
- int Array[] = new int [5];
Multidimensional Arrays (2D or 3D Array)
- an array containing one or more arrays as its element.
- int[][] twoD = new int [18] [36];
- char[][][] threeD = new char [10] [20] [30];
Sorting Arrays
- arranging the elements of an array in a particular order, such as
ascending or descending.
- Array.sort() method to sort arrays
Searching Arrays
- finding element in an array.
- Arrays.binarySearch() method to sort arrays
Adding and Removing Elements
- you can add new elements or remove an old one from an array.
Merging Arrays
- combines two or more arrays into a single array.
Passing Arrays as Parameters to Methods
- when passing an array as a parameter to a method in java, you’re
passing the reference to the array, not a copy of the array. This means
that changes made to the array inside the method will affect the
original array.
Modifying Elements of an Array in a Method
- when you modify elements of an array inside a method, the changes
are reflected in the original array.
Returning an Array from a Method
- you can return an array from a method by specifying the array type in
the method signature.
- ArrayList is one of the list implementation built atop an array, which is able to
dynamically grow and shrink as you add or remove elements. Elements could be easily
accessed by their indexes starting from zero.
- ArrayList is a generic class, so you can parameterize it with any type you want.
- List <String> list = new ArrayList<>();
Add Elements to the ArrayList
- you may insert an element either at the end or at the specific position.
Remove Elements from the ArrayList
- In order to remove an element, you should find its index an only then perform the
removal via remove() method.
Converting an ArrayList to an Array
- to convert an ArrayList to an Array in Java, use the toArray() method in List interface,
which returns an object array.
- the method will convert the list elements into the array without disrupting their order.
THANK YOU!!

You might also like