Because Java is too much of a pain in the ass to have included one in the standard library, here's a simple string join function:
public static String join(String[] pieces){
return join(pieces, " ");
}
public static String join(String[] pieces, char sep){
return join(pieces, String.valueOf(sep));
}
public static String join(String[] pieces, String sep){
if(pieces.length == 0) return "";
StringBuffer buf = new StringBuffer();
buf.append(pieces[0]);
for(int i=1,n=pieces.length; i<n; i++)
buf.append(sep).append(pieces[i]);
return buf.toString();
}
Update: Of course, there's also a join function in org.apache.commons.lang.StringUtils.
Because I always forget...
Perl heredoc syntax:
$_ = <<EOF;
text goes here
EOF
PHP heredoc syntax:
<?php
$str = <<<EOF
text goes here
EOF;
?>
Ruby heredoc syntax:
str = <<EOF
text goes here
EOF
Of course, Python's heredoc syntax is easy to remember:
str = """text goes here
"""
(text is on the same line as the """ for parity with the other examples)
new⇒Spider solitaire
I have now won, at the "Difficult"level, 186 games of SpiderSolitaire. I...
75.179.28.113: Oct 13, 9:34am