remove loop in linked list code example
Example 1: remove arraylist index in for loop
for (int i = data.size()-1; i >= 0; i--){
if (data.get(i).contains(element)){
data.remove(i);
}
}
Example 2: how to add a list in a list java
List<SomePojo> list = new ArrayList<SomePojo>();
List<SomePojo> anotherList = new ArrayList<SomePojo>();
anotherList.add(list);
Example 3: remove loop from linked list
Node remove(Node head){
Node slow=head;
Node fast=head;
while(slow!=null&&fast!=null&&fast.next!=null){
slow=slow.next;
fast=fast.next.next;
if(slow==fast){
if(slow==head){
while(slow.next!=head){
slow=slow.next;
}
slow.next=null;
}
if(slow==fast){
slow=head;
while(slow.next!=fast.next){
if(slow==fast.next){
fast.next=null;
}
slow=slow.next;
fast=fast.next;
}
fast.next=null;
}
}
}