I'm trying to examine an array of strings and find out which is the widest. Here's an approximation of the code I'm using:
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
| String [] texts = a bunch of texts
Font [] fonts = the fonts of those texts
double longestLine = ( the width of the first line, calculated using the font and the getStringBounds method) ;
double currentWidth ;
for ( int i=1 ; i < texts.length ; i ++ ) {
currentWidth = ( again using getStringBounds, this time to find the width of the current line ) ;
if ( longestLine < currentWidth )
longestLine = new Double ( currentWidth ).doubleValue () ;
}
|
So, here's my assignment question. What I really want to do in that last line is:
longestLine = currentWidth ;
except I suspect that will make longestLine and currentWidth both pointers to the same variable, and thus longestLine will change whenever currentWidth changes. That's not what I want. But using "new Double ( currentWidth ).doubleValue ()" seems like a really dumb way to do things. I mean, really: creating a Double from a double so that I can get a new double? That seems really roundabout. Is there a simpler way to do the same thing?