-
Notifications
You must be signed in to change notification settings - Fork 1
/
ToDoFunction.java
39 lines (34 loc) · 989 Bytes
/
ToDoFunction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.ToDo.subbu;
import java.util.ArrayList;
public class ToDoFunction {
private ArrayList<String> todoList= new ArrayList<String>();
//Add list item
public void addItem(String item) {
todoList.add(item);
}
//remove list item
public void removeItem(int index) {
String myItem = todoList.get(index);
todoList.remove(index);
}
//print the entire list
public void printTodoList() {
System.out.println("Todo list consists of :"+ todoList.size()+"items");
for(int i=0;i<todoList.size();i++) {
System.out.println("Item at position "+(i+1)+"is"+todoList.get(i));
}
}
public void updateTodo(int index, String list) {
todoList.set(index,list);
System.out.println("Updation completed at position"+index+1);
}
//search feature for user
public String findItem(String searchItem) {
int index = todoList.indexOf(searchItem);
if(index == -1) {
return null;
}else {
return todoList.get(index);
}
}
}