forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericArray.java
More file actions
38 lines (30 loc) · 752 Bytes
/
GenericArray.java
File metadata and controls
38 lines (30 loc) · 752 Bytes
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
package Week4;
public class GenericArray <T> {
T []arr;
int num=0;
public GenericArray() {
arr= (T[]) new Object[2];
}
public void add(T element){
if (num<=arr.length-1)
{
arr[num]=element;
num++;
}
}
public void print(){
for (int i = 0; i <arr.length ; i++) {
System.out.println(arr[i]);
}
}
public static void main(String[] args) {
GenericArray<Integer> a1=new GenericArray<>();
a1.add(11);
a1.add(112);
a1.print();
GenericArray<String> a2=new GenericArray<>();
a2.add("Ibrahim");
a2.add("Abdulraqeeb");
a2.print();
}
}