Semi-Structured Data and the Web – Day 3

Woah.

It always worries me a little when the greek symbols come out. So far, we’ve pretty much avoided them in the Semi-Structured Data and the Web course, so to see them today, whilst not really unexpected, did make my heart sink a little. Continue reading

Advertisements

Faster Java – Strings

If you’re building a long String in Java, don’t stick String objects together using ‘+’, for example:

String str = "Hello";
str = str + world;
str = str + "!";

Why not?

It’s really slow when you do it a lot!

What should you do instead?

Use the append(String) method in StringBuffer (Java 1.4.2 on), or StringBuilder (Java 5 on). StringBuilder is slightly faster than StringBuffer, but is not thread safe. Both are much faster than concatenating String objects – by orders of magnitude. For example:

StringBuffer str = new StringBuffer("Hello");
str.append(world);
str.append("!");

Continue reading