Getting started with DSA and competitive coding What you will learn Time complexity Space Complexity What are Arrays and how to work in Arrays How to handle String in Java What are Sets, Map, List, Stack and Queue How to Declare, use, and iterate – Sets, Map, List, Stack and Queue Description These notes contain […]
Getting started with DSA and competitive coding What you will learn Time complexity Space Complexity What are Arrays and how to work in Arrays How to handle String in Java What are Sets, Map, List, Stack and Queue How to Declare, use, and iterate – Sets, Map, List, Stack and Queue Description These notes contain basic details such as how to declare, initiate, access(add/remove), iterate arrays, set, list, map, queue, stack Arrays stores values of the same data type. The address of elements stored consecutively in memory
length is fixed. inserting or deleting an element in middle is not easy Declaration: int[] nums = {1,2,4} //initializing with values
int[] nums = new int[10] //initializing with size. 0 will be initialized in all indexes if we declare without variables Accessing an element: Array index starts from 0..length-1
int[] nums = {1,2,4}
nums[0] — 1
nums[1] — 2
nums[2] — 4 Built-in methods to use in Arrays Sorting an element — Arrays. sort(nums); Finding the size of array — array_name.length Filling array element with some values – Arrays. fill(nums, -1) -> this will assign all values in the array as -1 Iterating Arrays Let us consider we loop the elements in an integer array, we can do it like below 1. For loop: for (i = 0; i < nums.length; i++) { System.out.print(nums[i]); // accessing each element of array } 2. For each loop for (int i : nums) { System.out.print(i); } Strings Strings are nothing but a sequence of character values. They will be is written inside “ ”. Declaration Strins s = “Welcome”; // string literal String s= new String(“Welcome”); // string object The strings created like this are not mutable. If we want to add or delete anything from this string, we need to use StringBuilder or String Buffer class only Built-in methods: length of a string — length() seeing character at some position — charAt() if a string contains particular substring — contains() Converting string to char array — toCharArray() taking substrings — substring() Replacing in string — replace() Replacing first occurence — replaceFirst() joining two strings — string1. concat(string2) getting index of a character — string.indexOf(character) removes beginnind and ending space in string — trim() converting lower and capital letters inside string — toUpperCase() and toLowerCase() StringBuilder: StringBuilder is mutable. Declaration: StringBuilder string = new StringBuilder(“Welcome”); Built in methods used in String Builder: All string built in methods can be used here as well string. append(“strings”) — to append to a string string. insert(startIndex,”string”) — to insert a string from particular index string. delete(startIndex, endIndex) — deleted string from the start to given end index string. reverse() — to reverse the array Iterating String: For each loop: for (Char c : string.toCharArray()){
Who can apply
- Open to everyone with a Udemy account
What you get
- Learn at your own pace
How to apply
Open the course page and enroll
