I decided to go about and add a Java code snippet to my blog entry. I thought the way I'd achieve it is would be to surround it with a pre tags indicating preformatted text, but this didn't achieve the required result.
This is what I entered into the blog:
Code: Select all
<pre>
// Remove duplicates from a list in-place
private static <T extends Comparable<? super T>>
void removeDuplicates(List<T> list) {
Collections.sort(list);
int i = 0;
// once reached second last element, break
while (i < list.size() - 1) {
T t1 = list.get(i);
T t2 = list.get(i+1);
if (t1.compareTo(t2)) {
list.remove(i+1);
} else {
++i;
}
}
}
</pre>
Is there an easy way to post code in S9Y blog entries? Something like the wayyou can insert code into posts on this forum. I'm a developer, so it's really handy for me to able to do that. I'm sure other people would have come across this problem, but I haven't seen this mentioned in the FAQ or on the forum. If I've missed it, my apologies.
Thanks in advance!
Misha