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
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]
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
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
•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) 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!!
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) 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.
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) .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.
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.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
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 .
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
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
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.
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();
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.
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
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' .
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.)
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] 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) 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);
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);
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.
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.
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
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
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.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
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.
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.
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. 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]
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) 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.
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
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.
//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) 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) 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.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. 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;
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.
My two methods are: subList(starting from, ending + 1): it returns a portion of the arraylist where we can specify from which index we want to see till the end index. But note that here we add 1 because the ending index we define in the method is exclusive. So in order to see the desired portion we have to add 1 at the ending index. hashCode(): returns the hash code value for this list
subList(int fromindex,int toindex) --> This method returns a list that contains the elements from first index to the last index that you had given as parameters for this method trimToSize() --> This method sets the capacity of the array list to the current number of elements to manage storage of the data .
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
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] .subList(a,b) -> where a and b are the index in arraylist (a is included and b in excluded) 2] .hashCode() -> provides the hashcode value of the arrayList
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
subList(start index , end index) -> ye ek list return karta hai similar to the one in python for those who don't know python, ye function start se leke end-1 index tak ke elements ko [ big bracket] me enclose karke deta hai. retainAll(collection) -> ye sirf un elements ko arrayList me retain karta hai jo pass kiye hue collection me 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) "toArray()" : this method will convert the data type of all the elements from "Arraylist" to "Array" 2) "isEmpty()" : this method will check if the Arraylist is empty or not. If it is empty, it will return true.
removeRange : It helps you to remove the element from the from the first index till the index you want to removed. retainAll: It only provide the value which are actual present in the list. otherwise it will throw an exception ClassCastException
toArray() - Returns an array containing all of the elements in this list in proper sequence get(int index) - Returns the element at the specified position in this list.
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
removeRange(int fromIndex, int toIndex) ---> removes all the elements between 'fromIndex' and 'toIndex'. trimToSize() ---> trims the ArrayList's capacity to the current size. For example -> If u have set an ArrayList to be10 integers and u have added only 5 integers then this function will change the capacity from 10 to 5.
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
removeAll(collection c): Is method ka use karke ham hamare current collection mai se specified collection ke all elements ko remove kar sakte hain. subList(int fromIndex, int toIndex): Ye ek sublist return karega jisme vo element honge jo specified index range ke beech Mai honge. Note-> toIndex is exclusive.
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.
toArray() - This converts an Array list into an array. removeAll(Collection c) - Removes all elements from the arraylist which are present in the collection given in as argument.
1 . .equals(). returns true if the all elements in obj1 are present in obj2 in the same order and returns false if not present in obj2 or not in same order 2. .trimToSize(); this sets the size of the list from initial defined capacity to whatever number of elements currently in the list .
sublist(int start, int end) - returns a small list or a sub list of the main array list from the index start(main array list) to index end toArray()- returns an array version of our arraylist
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.
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
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!
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
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?
•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
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!!
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) 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
Thanks sir for providing a free java course..... did not even need to attend an extra class to learn java
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) .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.
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
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
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 .
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
from Hello world to arraylist is the sign of consistency thank you harry saab!.
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
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
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.
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
IsEmpty() - checks whether the list is empty or not
Replaceall(collection)- replaces the list with the provided 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();
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.
Two methods of ArrayList
1. isEmpty() :- Use to check whether the Arraylist is empty or not.
2. equal() :- Use to compare two ArrayList.
Best RUclips Channel In This Universe Even Aliens Agree To It, Thank You For This Much Great Content, Harry Sir
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
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' .
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.)
Harry Java ki series me Century ka liya advance me CONGRATULATIONS. 🥳🥳🎊🎉
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] 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) 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);
trimToSize( )==> Trims the capacity of the array list.
toArray( )==> Returns an Array containing all the elements from first to last.
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);
Two methods
1.Clone()- return a copy of the list.
2.equal()- this method compare the size of the two array List.
👍
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) l1.retainAll(l2) --> Only common elements are left in the l1 list
2)l1.remove(n)--> Removes the nth index of the 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
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
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
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.
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
*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
1. subList(int fromIndex, int toIndex) -> for making sub list of arry
2. trimToSize() -> for triming size of current arry
19:19
removeAll- removes elements between given index.
retainAll- removes all elements except for given by user
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.
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.
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. 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]
1) equals: compares the object with the collection for equality check
2)clone: It makes a copy of the desired arraylist
trimToSize() -> Basically sets the capacity of the ArrayList to current size
isEmpty() -> Tells whether ArrayList is empty
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
l1.add() -> adds the element in arraylist.
l1.get() -> used to get element from arraylist so that we can print the elements.
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'."
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.
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
l1.remove(6) removes the element which value is 6
l1.retainall(l2) gives only the elements which common in both l1 and l2
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.
Iterator ref_var= name_arraylist.iterator() -》 used to get values of each element of arraylist.
Clone()->make a shallow copy of arraylist
//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) 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) 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.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. 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;
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.
My two methods are:
subList(starting from, ending + 1): it returns a portion of the arraylist where we can specify from which index we want to see till the end index. But note that here we add 1 because the ending index we define in the method is exclusive. So in order to see the desired portion we have to add 1 at the ending index.
hashCode(): returns the hash code value for this list
subList(int fromindex,int toindex) --> This method returns a list that contains the elements from first index to the last index that you had given as parameters for this method
trimToSize() --> This method sets the capacity of the array list to the current number of elements to manage storage of the data .
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
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
Collection.sort(l) :- array ko sort krr da gaaa simplly
removerange(3,7) :- it remove all the element between 3 to 7
1] .subList(a,b) -> where a and b are the index in arraylist (a is included and b in excluded)
2] .hashCode() -> provides the hashcode value of the arrayList
L1.isEmpty();
Returns boolean
L1.removeRange(int fromIndex, int toIndex);
Reomve value b/w them including fromIndex excluding toIndex.
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
Harry sir we will be grateful if u help us in doing any major project in Java & C like u did in Python and thank u for helping us unconditionaly.
subList(start index , end index) -> ye ek list return karta hai similar to the one in python for those who don't know python, ye function start se leke end-1 index tak ke elements ko [ big bracket] me enclose karke deta hai.
retainAll(collection) -> ye sirf un elements ko arrayList me retain karta hai jo pass kiye hue collection me 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.
Bahi documentation sach me kamal h or samjh me aa rhi h bro wow so goooooooodd
1) "toArray()" : this method will convert the data type of all the elements from "Arraylist" to "Array"
2) "isEmpty()" : this method will check if the Arraylist is empty or not. If it is empty, it will return true.
bro is playlist ko krne ke baad keh skte hai ki hume core java ati hai??????? ya or bhi kuch reh gya h core sikhne ke liye
removeRange : It helps you to remove the element from the from the first index till the index you want to removed.
retainAll: It only provide the value which are actual present in the list. otherwise it will throw an exception ClassCastException
at 12.11 it is clarified.good job.
toArray() - Returns an array containing all of the elements in this list in proper sequence
get(int index) - Returns the element at the specified position in this list.
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
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...
😇😇
Thank u so much harry bhai mai aapka Course Starting se dhek raha hai hu
removeRange(int fromIndex, int toIndex) ---> removes all the elements between 'fromIndex' and 'toIndex'.
trimToSize() ---> trims the ArrayList's capacity to the current size.
For example -> If u have set an ArrayList to be10 integers and u have added only 5 integers then this function will change the capacity from 10 to 5.
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) l1.size ( ) -> Return the number of size in this collection.
2) l1.isEmpty( ) -> Return true when our method is empty otherwise return false.
1.
clone() :- Return a shallow copy of this ArrayList instance.
2.
is empty() :- Returns true if this list contains no elements.
👍👍🙏Thank u sir 🙏
removeAll(collection c): Is method ka use karke ham hamare current collection mai se specified collection ke all elements ko remove kar sakte hain.
subList(int fromIndex, int toIndex): Ye ek sublist return karega jisme vo element honge jo specified index range ke beech Mai honge.
Note-> toIndex is exclusive.
l1.subList(2,6) return a sublist form 2 to 6 index
l1.removeIf(n -> ((n % 3) == 0)); delete number which is divisable by 3 from the array
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.
Iterator()
List subList(int fromIndex, int toIndex);
toArray() - This converts an Array list into an array.
removeAll(Collection c) - Removes all elements from the arraylist which are present in the collection given in as argument.
1 .
.equals().
returns true if the all elements in obj1 are present in obj2 in the same order
and returns false if not present in obj2 or not in same order
2. .trimToSize();
this sets the size of the list from initial defined capacity to whatever number of elements currently in the list .
Thank you sir for such a very very beautiful course..
sublist(int start, int end) - returns a small list or a sub list of the main array list from the index start(main array list) to index end
toArray()- returns an array version of our arraylist
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.