F Insert

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

ArrayList;
import java.util.HashMap;
import java.util.Random;

public class F_Insert {


public static void main(String args[]) {
F_Insert f_insert = new F_Insert();
f_insert.insertValue(10);
f_insert.insertValue(30);
f_insert.insertValue(40);
f_insert.insertValue(80);
f_insert.insertValue(20);
f_insert.remove(20);
System.out.println(f_insert.random());
}

ArrayList<Integer> arrayList = new ArrayList<>();

void insertValue(int value) {


if (arrayList.contains(value)) {
return;
} else {
arrayList.add(value);
}
}

int remove(int value) {


if (arrayList.contains(value)) {
System.out.println("index of the value :" + arrayList.indexOf(value));
System.out.println("Deleted value: " + value);
arrayList.remove(arrayList.indexOf(value));
} else {
System.out.println("value is not present");
}
return 0;
}

int random() {
Random random = new Random();
if (arrayList.size() == 0) {
System.out.println("nothing is there to show");
return 0;
} else {
return arrayList.get(random.nextInt(arrayList.size()));
}
}
}

You might also like