-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerics.java
More file actions
66 lines (54 loc) · 1.06 KB
/
generics.java
File metadata and controls
66 lines (54 loc) · 1.06 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
*
*/
package Day6;
import java.util.Arrays;
public class generics
{
public static void main(String[] args)
{
System.out.println("Enter the Number :");
String t[]= {"naveen","balapraveen","baveen"};
Array ar=new Array(t);
ar.Sort(t);
System.out.println(Arrays.toString(ar.mark));
}
}
class Array <Type extends Comparable< Type>>
{ Type mark[];
Type temp;
int count=0;
Array( Type Marks[])
{
mark=Marks;
}
public void put(Type i)
{
mark[count++]=(Type)i;
}
public <T> Type[] Sort(Type Marks[])
{
for(int i=0;i<mark.length-1;i++)
{
for(int j=0;j<mark.length-i-1;j++)
{ String n1=(String) mark[j];
String n2=(String) mark[j+1];
int l1=n1.length();
int l2=n2.length();
if(l1>l2 )
{
temp=(Type) mark[j];
mark[j]=mark[j+1];
mark[j+1]= temp;
}
else if(l1==l2)
{
Type t=(Type) mark[j];
mark[j]=mark[j+1];
mark[j+1]= (Type) t;
}
}
}
return (Type[]) mark;
}
}