Skip to content

Instantly share code, notes, and snippets.

@Rohit-554
Created March 25, 2023 18:45
Show Gist options
  • Select an option

  • Save Rohit-554/49f1cc2538c2467fbfe8a9d58ec82a52 to your computer and use it in GitHub Desktop.

Select an option

Save Rohit-554/49f1cc2538c2467fbfe8a9d58ec82a52 to your computer and use it in GitHub Desktop.
import java.util.*;;
public class BriefExampleGC<T> {
private List<T> items;
public BriefExampleGC() {
this.items = new ArrayList<>();
}
public void add(T item) {
this.items.add(item);
}
public int size() {
return this.items.size();
}
public void display(){
System.out.println("The current list is :");
for(T x:items){
System.out.println(x);
}
}
public static void main(String[] args) {
BriefExampleGC<Integer> Mylist = new BriefExampleGC<Integer>();
Mylist.add(1);
Mylist.add(2);
Mylist.add(3);
System.out.println("List size " + Mylist.size());
Mylist.display();
BriefExampleGC<String> strList = new BriefExampleGC<String>();
strList.add("hello");
strList.add("world");
System.out.println("Size of strList: " + strList.size());
strList.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment