Array in DTA-1.pdf

Document Details

CoolestGothicArt1079

Uploaded by CoolestGothicArt1079

Bukidnon State University

Tags

data structures arrays Java programming

Full Transcript

IT 121 DATA STRUCTURE AND ALGORITHM ARRAY IN DATA STRUCTURE AND ALGORITHM INTRODUCTION OF ARRAY TOPICS KEY TOPICS DISCUSSED IN THIS PRESENTATION INTRODUCTION OF ARRAY DIMENSIONAL ARRAYS MANIPULATE VALUE OF ARRAY VARIABLE AND DATA TYPE https://medium.com/analytics-vidhya/data-stru...

IT 121 DATA STRUCTURE AND ALGORITHM ARRAY IN DATA STRUCTURE AND ALGORITHM INTRODUCTION OF ARRAY TOPICS KEY TOPICS DISCUSSED IN THIS PRESENTATION INTRODUCTION OF ARRAY DIMENSIONAL ARRAYS MANIPULATE VALUE OF ARRAY VARIABLE AND DATA TYPE https://medium.com/analytics-vidhya/data-structures-in-java-arrays-9a345c1c876c int x = 35 char y = Bob boolean z = true Array is a predefined variable with a data type that can hold a fixed number of values, altogether but in separate locations The array members should be in the same data type. We also can treat arrays as sets, well-defined sets. Elements Elements duplicate element Advantages of Arrays in Java Java arrays enable you to access any element randomly with the help of indexes It is easy to store and manipulate large data sets Disadvantages of Arrays in Java The size of the array cannot be increased or decreased once it is declared—arrays have a fixed size Java cannot store heterogeneous data. It can only store a single type of primitives How to declare an array in Java? dataType[] arrayName; How to declare an array in Java? dataType[] arrayName; dataType - it can be primitive data types like int, char, double, byte, etc. or Java objects arrayName - it is an identifier How to declare an array in Java? dataType[] arrayName; example double[] data; But, how many elements can array this hold? In Java, It can declare and allocate the memory of an array in one single statement. How to Initialize Arrays in Java? In the Java array, each memory location is associated with a number. The number is known as an array index. We can also initialize arrays in Java, using the index number. For example, Index = indices How to Access Elements of an Array in Java? Looping Through Array Elements https://www.programiz.com/java-programming/arrays Types of Arrays 1. One-dimensional Array 2. Two-dimensional Array 3. Multi-dimensional Array https://www.simplilearn.com/tutorials/java-tutorial/arrays-in-java 1. One-dimensional Array 2. Two-dimensional Array 2. Two-dimensional Array https://www.geeksforgeeks.org/jagged-array-in-java/ Syntax: data_type array_name[][] = new data_type[n][]; //n: no. of rows array_name[] = new data_type[n1] //n1= no. of columns in row-1 array_name[] = new data_type[n2] //n2= no. of columns in row-2 array_name[] = new data_type[n3] //n3= no. of columns in row-3... array_name[] = new data_type[nk] //nk=no. of columns in row-n 3. Multi-dimensional Array Initialization can be done like this int [ ] [ ] [ ] arr = new int; or int[ ][ ][ ] arr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } }; The syntax works like this. data type [ ][ ][ ] array name = new data type [array index][row index][column index]; Java Program to Concatenate Two Arrays Java Program to Concatenate Two Arrays HOW TO INSERT VALUE IN ARRAY? HOW TO INSERT VALUE IN ARRAY? HOW TO REMOVE VALUE IN ARRAY? IT 121 DATA STRUCTURE AND ALGORITHM ARRAYLIST ALGORITHM ARRAY VS ARRAYLIST ArrayList in Java, is a resizable-array implementation of the List interface. It implements all optional list operations and permits all elements, including null. ARRAY VS ARRAYLIST IN JAVA The main difference between array and arraylist is that arraylist can grow and shrink dynamically while an array cannot. An ArrayList is a re-sizable array, also called a dynamic array. It grows its size to accommodate new elements and shrinks the size when the elements are removed. ArrayList internally uses an array to store the elements. Just like arrays, It allows you to retrieve the elements by their index. Java ArrayList allows duplicate and null values. Java ArrayList is an ordered collection. It maintains the insertion order of the elements. You cannot create an ArrayList of primitive types like int, char etc. You need to use boxed types like Integer, Character, Boolean etc. Java ArrayList is not synchronized. If multiple threads try to modify an ArrayList at the same time, then the final outcome will be non-deterministic. You must explicitly synchronize access to an ArrayList if multiple threads are gonna modify it. How do you use an ArrayList? Import ArrayList Java https://www.programiz.com/java-programming/arraylist

Use Quizgecko on...
Browser
Browser