18:54 Two methods for Array List remove() -> takes the index of an element as an argument and then removes the element clear() -> removes all the element from array list. Thank You Harry bhaiya
L1.removeAll (l2) ~ used to remove all objects of l2 from l1 l1.removeIf (n-> (n% 5==0) ) ~ removes all elements from l1 if that element is divisible by 5
1) l1.subList(1,3) --> This method is used to get elements from index 1 to 3 (excluding 3) 2) l1.retainAll(l2) --> This method removes all elements from l1 that are not present in l2. Hence, only common elements are retained.
extending second example: what if we want to remove element which are common(opposite of retainAll) we will use l1.removeAll(l2) say l1=[1,2,3] l2=[3,4,5] then output will be [1,2]
Two additional methods of ArrayList : 1. isEmpty() method -> returns true if the array is empty (has no elements) 2. remove() method -> removes the element at the specified position
1) list_1.removeAll(collection list_2) :- Removes all elements in list_2 from list_1 eg. if list_1={1,3,5,6,7} and list_2={1,5,6} then after this code list_1 will be = {3,7}. 2) list_1.retainAll(collection list_2) :- Retains all elements in list_1 that are in list_2 and removes all other eg. if list_1={1,3,5,6,7} and list_2={1,5,6} then after this code list_1 will be = {1,5,6}. Thank you Harry Bhai!!
•subList(indexfirst, last index) It return subList from starting_index to lastIndex-1 ,which is stored in another arraylist. •toArray() This method return the array which contains all the elements of arrayList return object array Thanks bhaiya
removeRange( int starting index, last index) -->>> this removes elements in the arraylist. Starting index included and last index excluded.. *** This method has protected access...***
l1.sublist(3,6) -> This will return the value in the range of 3rd to 5th element which is stored in the array list l1.trimToSize() -> This will trim the left part of your array-like if you have given the space of 500 but you only used 240 so it will automatically delete the remaining element which will save the time of program and memory
1. Collections.sort(listname); This method is used sort the list is ascending order. 2.l1.retainAll(l2); this method will remove all values of l1 and will keep only l2 values The first one is very helpful use it.
1.Collections.sort(l1) which helps to sort the ArrayList in ascending order and for descending order Collections.sort(l1,Collections.reverserOrder()); 2.l1.replaceAll((n)->n+1); which helps to replace all the items in the list as an update
Methods I found are : 1) .clone() ----> This methods will give you a duplicate copy of the arrayList. 2) .sort(Comparator c) ----> This method will arrange your data or elements of an arraylist in ascending order. You can even put a custom Comparator for arranging your elements differently. Harry Bhai you have and are doing a great job. Thank you so much.
1. subList(int fromIndex, int toIndex) This function returns a portion of the array list from a specified index which is the fromIndex (inclusive) to a specified index which is toIndex (exclusive) . For example if the ArrayList l1 contains the following integer elements:- 788, 15, 18, 19, 1, 5, 6, 7, 4, 6, 676. The function l1.subList(2,5) will return the output as [18, 19, 1]. 2. retainAll( Collection c) This function returns all the elements of an arraylist which are a part of another arraylist. Example: l1 arraylist contains 1, 2, 3, 4 & l2 arraylist contains 1, 6, 7, 2 and then we are using the function l1.retainAll(l2) then l1 arraylist will retain only 1&2 elements. If we print l1 arraylist only 1 and 2 will be printed and if we print l2 arraylist then 1, 6, 7, 2 will be printed.
1.remove(Object o) Method ke throw hum Array list ke koi bhi element ko remove kr sakte he. 2.clone():-clone method ko throw hum koi bhi list ka clone kr sakte he Thank you Herry Bhai for this Confidence
removeRange(1,5)- will remove elements from index 1 to 5 Removeif (condition)- it will check condition if condition satisfied ,then it will remove that element.
1) remove(Object o) - removes the specified element from the list which appears for the first time in the list. 2) removeRange(int fromIndex, int toIndex) - removes the elements within the specified limits from the list.
Thank You Harry Bhai 😊 toArray() : This method will return an array containing all the elements in our ArrayList . Suppose our ArrayList is arr1 . To convert our ArrayList to an array we will do the following -> Code : int[] newArr = arr1.toArray();
1. removeIf(): removes elements from the list which satisfy the given condition. 2. trimToSize(): to save space reduces the remaining size of the defined ArrayList .
1) .isEmpty -> This function returns Boolean value whether the List is empty or not. 2) .remove(int index) -> This function removes the element at a particular index.
isEmpty() - It is type of method used to check that whether the arrayList contain some element or not .If it contain some element in it it means it will return 'true' otherwise 'false' . equals(Object o) - It is type of method used to check two array i.e whether the both are are equal or not if it is then it will return 'true' otherwise 'false' .
equals(Object o) :- Compares the specified object with this list for equality. get(int index) :- Returns the element at the specified position in this list.
Isempty() and toArray() the first one returns a boolean expression like if the arraylist is empty it returns true, and the second one is for printing the array in sequence from first to last.
18:54 1. trimToSize(): This method is used to minimize the storage of Arraylist to its current size 2. clone(): It mainly returns a copy of the arraylist - Shivam
Work Done. If we to check our array list is empty or not we can use isEmpty() method boolean a = l1.isEmpty(); System.out.println(a); // Returns a specific portion of our array while using subList(int fromIndex, int toIndex) method List x = l1.subList(1,4); System.out.println(x);
L1.isEmpty() -> returns true if the list is empty L1.removeAll() -> remove all the elements of list L1.subList(int startIndex, int endIndex) -> return list from startIndex to endIndex excluding endIndex
1. .isEmpty() --> to check if the list is empty or not will throw a boolean 2. .remove() -> if you specify the index inside the parenthesis the list will remove the obj from that particular index in the list Thank you harry love you
retainAll(Collection c) Retains only the elements in this list that are contained in the specified collection. toArray() Returns an array containing all of the elements in this list in proper sequence (from first to last element).
1.> hashCode() => hashCode() ek built-in method hai jo kisi object ke liye ek unique number (hash code) deta hai. Ye hash code object ki content aur memory address ke adhar par banata hai. 2.> toArray() -> ArrayList class ki ek method hai jo ArrayList ko ek array mein convert karke naya array return karti hai. Arrays static hote hain, yaani unka size fixed hota hai aur ek baar array banane ke baad hum uska size change nahi kar sakte. Lekin ArrayList dynamic hoti hai, iska size badal sakta hai jab hum elements ko add ya remove karte hain.
toArray - public T[] toArray(T[] a) Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
toArray() - Returns an array containing all of the elements in this list in proper sequence (from first to last element). trimToSize() - Trims the capacity of this ArrayList instance to be the list's current size.
1. remove (object k) : isme jo bhi index denge us index ki value remove ho jayegi 2. clone() : is method se ArrayList ka ek clone ya dublicate ArrayList ban jayega
1) Cloneing the L1,L2 list --> Object l3 = l1.clone(); // Clone the object for (Integer res : (ArrayList) l3) { System.out.println(res); } 2. Ensure capacity of list--> l2.ensureCapacity(10);
1] l1 .subList(int a,int b) -> Prints element of array l1 from index a to index b (a is included and b in excluded) 2] l1.hashCode() -> provides the hashcode value of the arrayList
toArray - returns object , i think it converts array list into array , i can perform array functions after i use l1.toArray sublist(3,6) - retuns arraylist , it will give sublist of 3,4,5 indexes
1) getLast() --> This Method is used to get a last element in the Collection 2) isEmpty() --> This method is used to return true if the list contains no element
l1.clone() Returns a shallow copy of this ArrayList instance. l1.toarray() returns an array with index from lfirst to last Harry bhai thanks for the course gonna finish it soon ..
(1) l1.clone() -> it gives the current copy of the l1 list . (2) ensureCapacity(int min Capacity) -> it set the minimum capacity of the list it be more as we required.
1>. l1.isEmpty() -: it return true if the list is empty , otherwise return false 2>. l1.trimToSize() -: it is used to trim the empty space in the Arraylist
removeRange(int fromIndex ,int toIndex); Iss method mei hum apne collection se particularly from index aur usko milakar se lekar to index exclusive thak apne array se remove karte hai. isEmpty(); yeh ek Boolean hai jo ki return true karega agar array mei koi element nhi hoga nhi toh false dega.
l1.hashCode() --> It will give us the hashCode value for the specific list. It is calculated based on the individual element's hash Value. l1.removeRange(int from , int to) --> It will remove the elements starting 'from' till the 'to'' index
1) isEmpty() ---> check whether the list is empty or not. return true if empty. 2) remove(Object o) ------> Remove the first occurence element from list if more than 2 same element present. 3) sublist() -----> make a other list from the parent list with the gived element range.
removeRange(int fromIndex, int toIndex) :- remove elements from the list between given index subList(int fromIndex, int toIndex) :- return the portion of the given list . for both methods :- 1st parameter index is inclusive 2nd parameter index is exclusive.
remove(Object o) -----removes the element "o" if present in the arrayList subList(int fromIndex, int toIndex)------ returns the elements from a specific index to a specific index
1. forEach() method The forEach loop helps iterate over each element of the list and perform specific operation inline. Here for each element of the ArrayList l1, it is being incremented by 1 and then added to a new ArrayList l2. Ex: ArrayList l1 = new ArrayList(); l1.add(3); l1.add(5); l1.add(2); l1.add(2); l1.add(6); l1.add(8); ArrayList l2; l1.forEach(number-> l2.add(number+1)); System.out.println(l1); System.out.println(l2); Output: [3, 5, 2, 2, 6, 8] [4, 6, 3, 3, 7, 9] 2. sublist(int fromIndex, int toIndex) method It returns a subset of the ArrayList within fromIndex to toIndex range (excluding toIndex) Ex: System.out.println(l1); l1.subList(2,5).clear(); System.out.println(l1); Output: [3, 5, 2, 2, 6, 8] [3, 5, 8]
l1.trimToSize() : The Capacity of Array will become equal to the capacity of Current Array Sout : l1.subList(Range of Index) : Helps in printing a Range out of Array
num.removeLast() -> Removes and returns the last element of this collection (optional operation). num.removeFirst() -> Removes and returns the first element of this collection (optional operation). 😀😎
1) l1.removeIf(n -> n > 30) then it will remove elements greater than 30 2) l1.ensureCapacity(10) , now it will ensure that arrayList has capacity of storing 10 elements. calling ensureCapacity with a value less than or equal to the current capacity has no effect. The ensureCapacity method is useful when you know in advance how many elements you are going to add to the ArrayList to minimize the number of reallocations
listIterator()-->ArrayList class is used to return a list iterator over the elements in this list (in proper sequence). toArray() -->This method return the array which contains all the elements of arrayList return object array
1) l1.subList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. 2)l1.hashCode() Returns the hash code value for this list.
1.). toArray - ek esa array return krta hai jisme saare elements proper sequence me hote hain. 2.) removesAll - ye method unn sabhi elements ko remove kar dega jo ek specified collection me hain
1. set(int index, int element) : ye ksi index pe ek element ko replace kr deta hai; 2. removeRange(int from, int to) : ye ek specified index se leke specified index tk list ko clear kr deta hai;
Collections.sort(list_name) : it sort the arraylist. TrimToSize(list_name) : it teduce the arraylist size equal to the number of element exist in arraylist.
1) removeFirst() ----> Removes and returns the first element of this collection (optional operation). 2) removeRange(int fromIndex, int toIndex)-----> Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
//two new element for learning! System.out.println(l1.isEmpty() + (" -> Not Empty")); System.out.println(l1.subList(0,5)); System.out.println(l1.retainAll(l2)); l1.trimToSize();
1) size() :- it will return the total number of elements in list 2) removeAll( arrayList ) :- it will remove all the elements from the list which are in arrayList.
toArray() - will make the arraylist an array trimToSize() - if we have 100 size elemetn but the arraylist has only 6 elements,after applying this ,the arraylist will have its size reduced to 6
Remove (int index) ==> It is remove elements from the specific position. trimToSize() ==> Trims the capacity of this ArrayList instance to be the list's current size.
*L1.remove(any integer you have given):-it removes the element from the array *Sout(l1.clone());->prints a copy of integers you have given in l1 *Sout(subList(2,3)):-> prints the integers from index 2 to 3 in array *l1.clear()->removes all integers of l1
remove(int index) -- remove the element, whose index we write in function trimToSize()--- it will trim the size of arraylist according to the element present , basically remove extra space.
set: replaces the element which you want to add with the element which is present in that particular index. removeRange: removes group of elements within selected range
removeRange(int fromIndex, int toIndex) -> ye method kis index se kha tak elements remove karne h waha kaam aata h trimToSize() -> ArrayList ki Capacity ko uske size ke equal kardega
1. System.out.println(l1.clone());// clone() method-> Returns a shallow copy of of this ArrayList Instance 2.. System.out.println(l1.subList(2,3));//Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
grateful to learn from you sir!! Your efforts are truly commendable this course has helped me learn oops in java and score well in my college examinations as well.
18:54
Two methods for Array List
remove() -> takes the index of an element as an argument and then removes the element
clear() -> removes all the element from array list.
Thank You Harry bhaiya
L1.removeAll (l2) ~ used to remove all objects of l2 from l1
l1.removeIf (n-> (n% 5==0) ) ~ removes all elements from l1 if that element is divisible by 5
thanks ..ye removeIf useful hai
Btw, the second Method, l1.removeIf (n-> (n% 5==0) ), appears to be a Lambda Expression, I'm not sure.
lambda
Wow
thankyou
1) l1.subList(1,3) --> This method is used to get elements from index 1 to 3 (excluding 3)
2) l1.retainAll(l2) --> This method removes all elements from l1 that are not present in l2. Hence, only common elements are retained.
notes???
Wow! Great thanks for sharing these are new for me
extending second example:
what if we want to remove element which are common(opposite of retainAll)
we will use l1.removeAll(l2)
say l1=[1,2,3]
l2=[3,4,5]
then output will be [1,2]
L1.clear();
Used to clear the array
L1.set(2,555);
Replace or store the element 555 in 2nd index of array
like intersection!
Two additional methods of ArrayList :
1. isEmpty() method -> returns true if the array is empty (has no elements)
2. remove() method -> removes the element at the specified position
can you please give the link of those methods?
1) list_1.removeAll(collection list_2) :- Removes all elements in list_2 from list_1
eg. if list_1={1,3,5,6,7} and list_2={1,5,6} then after this code list_1 will be = {3,7}.
2) list_1.retainAll(collection list_2) :- Retains all elements in list_1 that are in list_2 and removes all other eg. if list_1={1,3,5,6,7} and list_2={1,5,6} then after this code list_1 will be = {1,5,6}.
Thank you Harry Bhai!!
•subList(indexfirst, last index)
It return subList from starting_index to lastIndex-1 ,which is stored in another arraylist.
•toArray()
This method return the array which contains all the elements of arrayList
return object array
Thanks bhaiya
removeRange( int starting index, last index) -->>> this removes elements in the arraylist. Starting index included and last index excluded..
*** This method has protected access...***
ye bhi batate ki sublist ko try catch mei wrap krna padta hai use krne keliye for indexoutofbound exception and illegalargumentexception
l1.sublist(3,6) -> This will return the value in the range of 3rd to 5th element which is stored in the array list
l1.trimToSize() -> This will trim the left part of your array-like if you have given the space of 500 but you only used 240 so it will automatically delete the remaining element which will save the time of program and memory
Make a project in Java also as you made different projects in Python .
yes bhaiya please please
yes please
Yes bhai please make projects using Java.
yes please... 🙏🙏
Yes plz
Thanks sir for providing a free java course..... did not even need to attend an extra class to learn java
1. Collections.sort(listname);
This method is used sort the list is ascending order.
2.l1.retainAll(l2);
this method will remove all values of l1 and will keep only l2 values
The first one is very helpful use it.
trimToSize() ->trims the size of the array
removeRange(int fromIndex,int toIndex) ->remove elements between the given range
1.Collections.sort(l1) which helps to sort the ArrayList in ascending order and for descending order Collections.sort(l1,Collections.reverserOrder());
2.l1.replaceAll((n)->n+1); which helps to replace all the items in the list as an update
Methods I found are :
1) .clone() ----> This methods will give you a duplicate copy of the arrayList.
2) .sort(Comparator c) ----> This method will arrange your data or elements of an arraylist in ascending order. You can even put a custom Comparator for arranging your elements differently.
Harry Bhai you have and are doing a great job. Thank you so much.
Harry Java ki series me Century ka liya advance me CONGRATULATIONS. 🥳🥳🎊🎉
1. subList(int fromIndex, int toIndex)
This function returns a portion of the array list from a specified index which is the fromIndex (inclusive) to a specified index which is toIndex (exclusive) . For example if the ArrayList l1 contains the following integer elements:- 788, 15, 18, 19, 1, 5, 6, 7, 4, 6, 676. The function l1.subList(2,5) will return the output as [18, 19, 1].
2. retainAll( Collection c)
This function returns all the elements of an arraylist which are a part of another arraylist.
Example:
l1 arraylist contains 1, 2, 3, 4 & l2 arraylist contains 1, 6, 7, 2 and then we are using the function l1.retainAll(l2) then l1 arraylist will retain only 1&2 elements. If we print l1 arraylist only 1 and 2 will be printed and if we print l2 arraylist then 1, 6, 7, 2 will be printed.
1.remove(Object o) Method ke throw hum Array list ke koi bhi element ko remove kr sakte he.
2.clone():-clone method ko throw hum koi bhi list ka clone kr sakte he
Thank you Herry Bhai for this Confidence
from Hello world to arraylist is the sign of consistency thank you harry saab!.
removeRange(1,5)- will remove elements from index 1 to 5
Removeif (condition)- it will check condition if condition satisfied ,then it will remove that element.
nhi run hue dono
nhi chl rhe bhai 1 bar check kar lena
IsEmpty() - checks whether the list is empty or not
Replaceall(collection)- replaces the list with the provided list
1) remove(Object o) - removes the specified element from the list which appears for the first time in the list.
2) removeRange(int fromIndex, int toIndex) - removes the elements within the specified limits from the list.
Method 2 does not exist's
Thank You Harry Bhai 😊
toArray() :
This method will return an array containing all the elements in our ArrayList .
Suppose our ArrayList is arr1 . To convert our ArrayList to an array we will do the following ->
Code :
int[] newArr = arr1.toArray();
19:44 two methods are
✓get(index no) gives the element present at that number
✓isEmpty() checks whether the Array list is empty or not
1. removeIf(): removes elements from the list which satisfy the given condition.
2. trimToSize(): to save space reduces the remaining size of the defined ArrayList .
Best TH-cam Channel In This Universe Even Aliens Agree To It, Thank You For This Much Great Content, Harry Sir
1) .isEmpty -> This function returns Boolean value whether the List is empty or not.
2) .remove(int index) -> This function removes the element at a particular index.
isEmpty() - It is type of method used to check that whether the arrayList contain some element or not .If it contain some element in it it means it will return 'true' otherwise 'false' .
equals(Object o) - It is type of method used to check two array i.e whether the both are are equal or not if it is then it will return 'true' otherwise 'false' .
equals(Object o) :- Compares the specified object with this list for equality.
get(int index) :- Returns the element at the specified position in this list.
Isempty() and toArray() the first one returns a boolean expression like if the arraylist is empty it returns true, and the second one is for printing the array in sequence from first to last.
thanks bro
Haarry Bhiya is just Amazing Love U....🥰🥰🥰🥰🥰🥰🥰🥰🥰🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🥀🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹
18:54
1. trimToSize(): This method is used to minimize the storage of Arraylist to its current size
2. clone(): It mainly returns a copy of the arraylist
- Shivam
Work Done.
If we to check our array list is empty or not we can use isEmpty() method
boolean a = l1.isEmpty();
System.out.println(a);
// Returns a specific portion of our array while using subList(int fromIndex, int toIndex) method
List x = l1.subList(1,4);
System.out.println(x);
L1.isEmpty() -> returns true if the list is empty
L1.removeAll() -> remove all the elements of list
L1.subList(int startIndex, int endIndex) -> return list from startIndex to endIndex excluding endIndex
1. .isEmpty() --> to check if the list is empty or not will throw a boolean
2. .remove() -> if you specify the index inside the parenthesis the list will remove the obj from that particular index in the list
Thank you harry love you
1.
clone() :- Return a shallow copy of this ArrayList instance.
2.
is empty() :- Returns true if this list contains no elements.
👍👍🙏Thank u sir 🙏
Two methods of ArrayList
1. isEmpty() :- Use to check whether the Arraylist is empty or not.
2. equal() :- Use to compare two ArrayList.
retainAll(Collection c)
Retains only the elements in this list that are contained in the specified collection.
toArray()
Returns an array containing all of the elements in this list in proper sequence (from first to last element).
trimToSize() -> Basically sets the capacity of the ArrayList to current size
isEmpty() -> Tells whether ArrayList is empty
Two methods
1.Clone()- return a copy of the list.
2.equal()- this method compare the size of the two array List.
👍
1.> hashCode() => hashCode() ek built-in method hai jo kisi object ke liye ek unique number (hash code) deta hai. Ye hash code object ki content aur memory address ke adhar par banata hai.
2.> toArray() -> ArrayList class ki ek method hai jo ArrayList ko ek array mein convert karke naya array return karti hai.
Arrays static hote hain, yaani unka size fixed hota hai aur ek baar array banane ke baad hum uska size change nahi kar sakte. Lekin ArrayList dynamic hoti hai, iska size badal sakta hai jab hum elements ko add ya remove karte hain.
1) l1.retainAll(l2) --> Only common elements are left in the l1 list
2)l1.remove(n)--> Removes the nth index of the list
toArray - public T[] toArray(T[] a)
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.
If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
toArray() - Returns an array containing all of the elements in this list in proper sequence (from first to last element).
trimToSize() - Trims the capacity of this ArrayList instance to be the list's current size.
1. remove (object k) : isme jo bhi index denge us index ki value remove ho jayegi
2. clone() : is method se ArrayList ka ek clone ya dublicate ArrayList ban jayega
Congratulations for 950k subscribers 🔥🔥🔥
1) Cloneing the L1,L2 list -->
Object l3 = l1.clone(); // Clone the object
for (Integer res : (ArrayList) l3) {
System.out.println(res);
}
2. Ensure capacity of list-->
l2.ensureCapacity(10);
l1.remove(6) removes the element which value is 6
l1.retainall(l2) gives only the elements which common in both l1 and l2
trimToSize( )==> Trims the capacity of the array list.
toArray( )==> Returns an Array containing all the elements from first to last.
1. toArray() -> Used to make an array from an ArrayList.
2. ensureCapacity() -> Used to set the capacity of the ArrayList.
1] l1 .subList(int a,int b) -> Prints element of array l1 from index a to index b (a is included and b in excluded)
2] l1.hashCode() -> provides the hashcode value of the arrayList
1) Collection.sort(1); = This number will sort the number from less to high
2) l1.remove(2) = Its delete / remove the number in that element...
😇😇
Nice explanation sir thankyou so much 🙏🏼🙏🏼🙏🏼
Thank you sir for such a very very beautiful course..
1. subList(int fromIndex, int toIndex) -> for making sub list of arry
2. trimToSize() -> for triming size of current arry
toArray - returns object , i think it converts array list into array , i can perform array functions after i use l1.toArray
sublist(3,6) - retuns arraylist , it will give sublist of 3,4,5 indexes
1) getLast() --> This Method is used to get a last element in the Collection
2) isEmpty() --> This method is used to return true if the list contains no element
l1.clone() Returns a shallow copy of this ArrayList instance.
l1.toarray() returns an array with index from lfirst to last
Harry bhai thanks for the course gonna finish it soon ..
(1) l1.clone() -> it gives the current copy of the l1 list .
(2) ensureCapacity(int min Capacity) -> it set the minimum capacity of the list it be more as we required.
Iterator ref_var= name_arraylist.iterator() -》 used to get values of each element of arraylist.
Clone()->make a shallow copy of arraylist
1>. l1.isEmpty() -: it return true if the list is empty , otherwise return false
2>. l1.trimToSize() -: it is used to trim the empty space in the Arraylist
removeRange(int fromIndex ,int toIndex);
Iss method mei hum apne collection se particularly from index aur usko milakar se lekar to index exclusive thak apne array se remove karte hai.
isEmpty();
yeh ek Boolean hai jo ki return true karega agar array mei koi element nhi hoga nhi toh false dega.
l1.add() -> adds the element in arraylist.
l1.get() -> used to get element from arraylist so that we can print the elements.
l1.hashCode() --> It will give us the hashCode value for the specific list. It is calculated based on the individual element's hash Value.
l1.removeRange(int from , int to) --> It will remove the elements starting 'from' till the 'to'' index
Can't wait for 1 million subscribers
I subscribed you when you are at 2 lakhs but now sir 1 million
Amazing ❤️❤️
Love you sir ji
From punjab❤️🔥🎉
1) equals: compares the object with the collection for equality check
2)clone: It makes a copy of the desired arraylist
1) isEmpty() ---> check whether the list is empty or not. return true if empty.
2) remove(Object o) ------> Remove the first occurence element from list if more than 2 same element present.
3) sublist() -----> make a other list from the parent list with the gived element range.
removeRange(int fromIndex, int toIndex) :- remove elements from the list between given index
subList(int fromIndex, int toIndex) :- return the portion of the given list .
for both methods :- 1st parameter index is inclusive 2nd parameter index is exclusive.
remove(Object o) -----removes the element "o" if present in the arrayList
subList(int fromIndex, int toIndex)------ returns the elements from a specific index to a specific index
1. forEach() method
The forEach loop helps iterate over each element of the list and perform specific operation inline.
Here for each element of the ArrayList l1, it is being incremented by 1 and then added to a new ArrayList l2.
Ex:
ArrayList l1 = new ArrayList();
l1.add(3);
l1.add(5);
l1.add(2);
l1.add(2);
l1.add(6);
l1.add(8);
ArrayList l2;
l1.forEach(number-> l2.add(number+1));
System.out.println(l1);
System.out.println(l2);
Output:
[3, 5, 2, 2, 6, 8]
[4, 6, 3, 3, 7, 9]
2. sublist(int fromIndex, int toIndex) method
It returns a subset of the ArrayList within fromIndex to toIndex range (excluding toIndex)
Ex:
System.out.println(l1);
l1.subList(2,5).clear();
System.out.println(l1);
Output:
[3, 5, 2, 2, 6, 8]
[3, 5, 8]
l1.trimToSize() : The Capacity of Array will become equal to the capacity of Current Array
Sout : l1.subList(Range of Index) : Helps in printing a Range out of Array
num.removeLast() -> Removes and returns the last element of this collection (optional operation). num.removeFirst() -> Removes and returns the first element of this collection (optional operation). 😀😎
1) l1.removeIf(n -> n > 30) then it will remove elements greater than 30
2) l1.ensureCapacity(10) , now it will ensure that arrayList has capacity of storing 10 elements. calling ensureCapacity with a value less than or equal to the current capacity has no effect. The ensureCapacity method is useful when you know in advance how many elements you are going to add to the ArrayList to minimize the number of reallocations
listIterator()-->ArrayList class is used to return a list iterator over the elements in this list (in proper sequence).
toArray() -->This method return the array which contains all the elements of arrayList return object array
1) l1.subList(int fromIndex, int toIndex)
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
2)l1.hashCode()
Returns the hash code value for this list.
1.). toArray - ek esa array return krta hai jisme saare elements proper sequence me hote hain.
2.) removesAll - ye method unn sabhi elements ko remove kar dega jo ek specified collection me hain
add "()" with these methods
pls upload java data structure course as well.
1. isEmpty(): This method is used to check if the ArrayList 'marks' is empty.
It returns 'True' if the ArrayList is empty and 'False' if it is not."
2. // retainAll(Collection c)
mark1.retainAll(mark2);//-> This method retains only the common elements in 'mark2' when compared with 'mark1'."
you made this looks too easy i have been trying to understand this package, BTW THANKS
1. set(int index, int element) : ye ksi index pe ek element ko replace kr deta hai;
2. removeRange(int from, int to) : ye ek specified index se leke specified index tk list ko clear kr deta hai;
Feeling blessed sir ,for the way you teach us is outstanding
great you are very great teacher and programmer
1) l1.size ( ) -> Return the number of size in this collection.
2) l1.isEmpty( ) -> Return true when our method is empty otherwise return false.
Collections.sort(list_name) : it sort the arraylist.
TrimToSize(list_name) : it teduce the arraylist size equal to the number of element exist in arraylist.
1) removeFirst() ----> Removes and returns the first element of this collection (optional operation).
2) removeRange(int fromIndex, int toIndex)-----> Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
//two new element for learning!
System.out.println(l1.isEmpty() + (" -> Not Empty"));
System.out.println(l1.subList(0,5));
System.out.println(l1.retainAll(l2));
l1.trimToSize();
1) size() :- it will return the total number of elements in list
2) removeAll( arrayList ) :- it will remove all the elements from the list which are in arrayList.
19:19
removeAll- removes elements between given index.
retainAll- removes all elements except for given by user
toArray() - will make the arraylist an array
trimToSize() - if we have 100 size elemetn but the arraylist has only 6 elements,after applying this ,the arraylist will have its size reduced to 6
Your playlist looks like a ready made halwa for me....I'm so hungry!!!!!
1.isEmpty() checks if list has no elements or not.
2.Iterator() returns an iterator over elements in list
Remove (int index) ==> It is remove elements from the specific position.
trimToSize() ==> Trims the capacity of this ArrayList instance to be the list's current size.
*L1.remove(any integer you have given):-it removes the element from the array
*Sout(l1.clone());->prints a copy of integers you have given in l1
*Sout(subList(2,3)):-> prints the integers from index 2 to 3 in array
*l1.clear()->removes all integers of l1
it does not remove integer given.. it removes the integer at that index
Collection.sort(l) :- array ko sort krr da gaaa simplly
removerange(3,7) :- it remove all the element between 3 to 7
trimToSize() it reduce the size to index that are filled
removeAll(List2) removes elements of list1 that are present in List 2
remove(int index) -- remove the element, whose index we write in function
trimToSize()--- it will trim the size of arraylist according to the element present , basically remove extra space.
set: replaces the element which you want to add with the element which is present in that particular index.
removeRange: removes group of elements within selected range
removeRange(int fromIndex, int toIndex) -> ye method kis index se kha tak elements remove karne h waha kaam aata h
trimToSize() -> ArrayList ki Capacity ko uske size ke equal kardega
1 - sout(l1.isEmpty()); - false
2- sout(l1.iterator()); - Java.util.ArrayList$List@Itr@6acbcfc0
3 - sout(l.remove(index:7)); - 6
4- sout (l.remove(index:4)): - 6
20:07
1. System.out.println(l1.clone());// clone() method-> Returns a shallow copy of of this ArrayList Instance
2.. System.out.println(l1.subList(2,3));//Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
Thank u so much harry bhai mai aapka Course Starting se dhek raha hai hu
grateful to learn from you sir!! Your efforts are truly commendable
this course has helped me learn oops in java and score well in my college examinations as well.