clear an array list in java
// Creates an array list
ArrayList<String> arrayList = new ArrayList<>();
// Adds stuff to array list
arrayList.add("test");
// Clears array list
arrayList.clear();
clear an array list in java
// Creates an array list
ArrayList<String> arrayList = new ArrayList<>();
// Adds stuff to array list
arrayList.add("test");
// Clears array list
arrayList.clear();
ArrayList clear() method in java
import java.util.ArrayList;
public class ArrayListClearMethodExample
{
public static void main(String[] args)
{
ArrayList<Integer> al = new ArrayList<Integer>(4);
al.add(9);
al.add(3);
al.add(5);
al.add(1);
System.out.println("ArrayList before clear() method: " + al);
al.clear();
System.out.println("ArrayList after clear() method: " + al);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us