hi,
The following program for sorting a vector of objects based on partNo, now this was working in jdk1.2.2 but now since i have to use jdk1.1.8 , the Vector.get() and Vector.set() methods are not included, can i use any other alternative ????
import java.util.*;
public class sortTest
{
String partNo=null,customerName=null,subCustomerName=null,rotableCode=null;
int partQty;
public sortTest(String partNo)
{
this.partNo=partNo;
}
public sortTest(String partNo,String customerName,String
subCustomerName,String rotableCode,int partQty)
{
this.partNo=partNo;
this.customerName=customerName;
this.subCustomerName=subCustomerName;
this.rotableCode=rotableCode;
this.partQty=partQty;
}
public String getpart()
{
return partNo;
}
public String getcust()
{
return customerName;
}
public String getsubcust()
{
return subCustomerName;
}
public String getrot()
{
return rotableCode;
}
public int getqty()
{
return partQty;
}
public static void main(String args[])
{
sortTest temp;
Vector v=new Vector();
v.addElement(new sortTest("9373","ONT","AC","EX",10));
v.addElement(new sortTest("1373","ONT","AC","EX",10));
v.addElement(new sortTest("7233","ONT","AC","EX",10));
v.addElement(new sortTest("3743","ONT","AC","EX",10));
String a=null,b=null;
sortTest st = null;
for (int i=0 ; i<v.size() ; i++)
for (int j = i + 1 ; j < v.size(); j++)
if
(((sortTest)v.elementAt(i)).getpart().compareTo(((sortTest)v.elementAt(j)).getpart())
> 0)
{
st = (sortTest)v.get(i); ***
v.set(i, v.get(j)); ***
v.set(j, st); ***
}
for (int i=0 ; i<v.size() ; i++)
System.out.println( ((sortTest)v.elementAt(i)).getpart() );
}
}
The following program for sorting a vector of objects based on partNo, now this was working in jdk1.2.2 but now since i have to use jdk1.1.8 , the Vector.get() and Vector.set() methods are not included, can i use any other alternative ????
import java.util.*;
public class sortTest
{
String partNo=null,customerName=null,subCustomerName=null,rotableCode=null;
int partQty;
public sortTest(String partNo)
{
this.partNo=partNo;
}
public sortTest(String partNo,String customerName,String
subCustomerName,String rotableCode,int partQty)
{
this.partNo=partNo;
this.customerName=customerName;
this.subCustomerName=subCustomerName;
this.rotableCode=rotableCode;
this.partQty=partQty;
}
public String getpart()
{
return partNo;
}
public String getcust()
{
return customerName;
}
public String getsubcust()
{
return subCustomerName;
}
public String getrot()
{
return rotableCode;
}
public int getqty()
{
return partQty;
}
public static void main(String args[])
{
sortTest temp;
Vector v=new Vector();
v.addElement(new sortTest("9373","ONT","AC","EX",10));
v.addElement(new sortTest("1373","ONT","AC","EX",10));
v.addElement(new sortTest("7233","ONT","AC","EX",10));
v.addElement(new sortTest("3743","ONT","AC","EX",10));
String a=null,b=null;
sortTest st = null;
for (int i=0 ; i<v.size() ; i++)
for (int j = i + 1 ; j < v.size(); j++)
if
(((sortTest)v.elementAt(i)).getpart().compareTo(((sortTest)v.elementAt(j)).getpart())
> 0)
{
st = (sortTest)v.get(i); ***
v.set(i, v.get(j)); ***
v.set(j, st); ***
}
for (int i=0 ; i<v.size() ; i++)
System.out.println( ((sortTest)v.elementAt(i)).getpart() );
}
}