Friday, May 26, 2006
Java formatting progress
Java 1.4
private String getUrl() {
Object params = new Object[] {
m_host, Integer.toString(m_port)
};
return MessageFormat.format("ldap://{0}:{1}", params);
}
Java 1.5 argv and autoboxing...
private String getUrl() {
return MessageFormat.format("ldap://{0}:{1}", m_host, m_port);
}
Java 1.5 String.format
private String getUrl() {
return String.format("ldap://%s:%d", m_host, m_port);
}
you can get rid of String. using static import but I am not sure I like it
import static java.lang.String.format;
....
private String getUrl() {
return format("ldap://%s:%d", m_host, m_port);
}
of course Ruby is still better:
def get_url
"ldap://#{@host}:#{@port}"
end