I am working with Arraylist of objects. while i already succeeded in delete values from Arraylist while they are numeral.
i'm having trouble delete from arraylist while they are String here is the example :
public class ArrayListDemo {
public static void main(String[] args) {
// create an empty array list with an initial capacity
ArrayList<Namer> arrlist = new ArrayList<Namer>( );
// use add() method to add values in the list
arrlist.add(new Namer("1","A","G"));
arrlist.add(new Namer("2","E","G"));
arrlist.add(new Namer("3","F","G"));
System.out.println("Size of list: " + arrlist.size());
// let us print all the values available in list
for (Namer value : arrlist) {
System.out.println("age = " + value.age);
}
arrlist.remove("3");
System.out.println("Now, Size of list: " + arrlist.size());
for (Namer value : arrlist) {
System.out.println("age = " + value.age); //System.out.println("Value = " + value);
}
}
}
and the result of running it proof it doesnt deleted the spesific row i need to delete if with String and cant use number as "Key" .
Size of list: 3
age = 1
age = 2
age = 3
Now, Size of list: 3
age = 1
age = 2
age = 3
what can i make it to work with String in order to delete ?
if that's help
this is the object of arrayList
public class Namer
{
// instance variables - replace the example below with your own
public String age;
public String name;
public String L_name;
public Namer(String a, String na , String Lname)
{
// initialise instance variables
age =a;
name=na;
L_name=Lname;
}
}