Created
March 25, 2023 18:45
-
-
Save Rohit-554/49f1cc2538c2467fbfe8a9d58ec82a52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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