Member-only story

A StringBuilder for Swift

You shouldn’t do this

Steven Curtis
4 min readJan 6, 2023
Photo by Steve Johnson on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 14.2, and Swift 5.7.2

I remember taking part in an interview where one of the interviewers asked which language I knew best. The answer?

swift

He followed up.

“No, which language do you know best. It’s Ok, which one. I’m from a Java background.”

It really trips up a candidate when an interviewer makes an assumption, and then makes a second assumption that you’re so stupid that you don’t understand the initial question.

The Question

So his question wasn’t about a StringBuilder Class, but the point is that for wider understanding it is worth knowing about the class in Java and the equivalents in Swift. This can aid communication with other programmers, which is never a bad thing.

A StringBuilder in Java

In Java a StringBuilder is used to create a mutable collection of characters. The important property for StringBuilder is the fact that it is indeed mutable.

This is in contrast to the String class in Java, which represents an immutable collection of characters.

--

--

No responses yet