The original question I posted on Yahoo Answers:
I can't get this code to return anything:
In NewVector.java: a class that extends Vector:
public Object getSmallest()
{
Object obj = elementData[0];
try
{
String a = (String)elementData[0];
for(int i=1;i<elementCount;i++)
{
String b = (String)elementData[i];
if(a.compareTo(b)>0)
{
a = b;
obj = elementData[i];
}
}
}
catch(NullPointerException e)
{
}
return obj;
}
in StringVector.java: a vector holding class that just holds objects that holds and does stuff with strings(StringElement):
public String getSmallest()
{
return strings.getSmallest().toString();
}
and the driver:
else if(num==8)
{
System.out.println(vect.getSmalle…
}
No idea whats going on. Any ideas?
I was curious, since I want NewVector to be able to work with any kind of data structure, be it char, double or some construct, would I be able to do something like:
Object a = something;
String b = a.toString();
What would be the best way of doing this?