Ugo Posada
Posts: 37
Nickname: binaryx
Registered: Dec, 2002
|
|
Re: String arrays
|
Posted: Jan 10, 2003 10:11 AM
|
|
I couldn't quite understand your question but I wrote a program that gives the lower and higher strings based on the lexicographical order, I hope it is what you need.
import java.util.Vector;
import java.util.Collections;
public class MinMax {
private Vector stringVector;
public MinMax(String[] input) {
stringVector = new Vector();
for (int i = 0; i < input.length; i++) {
stringVector.addElement( input[i].toLowerCase() );
}
Collections.sort(stringVector);
}
public String getMin() {
return (String) stringVector.firstElement();
}
public String getMax() {
return (String) stringVector.lastElement();
}
public static void main(String[] args) {
String[] input = {"Pear", "airplane", "Zippo", "deer"};
MinMax myMinMax = new MinMax(input);
System.out.println( "Minimum value is: "+ myMinMax.getMin() );
System.out.println( "Maximum value is: "+ myMinMax.getMax() );
}
}
|
|