Scala tip: How to extract a field from a sequence of objects to create a new sequence

As a brief Scala tip, a fun thing you can do with the map method on Scala sequences (Array, List, Seq, Vector, etc.) is to convert a sequence of objects into a sequence of something else, typically extracting a field from the original object to create the new sequence.

For instance, imagine that you have a case class named Person that has two constructor parameters, firstName and lastName:

How to parse JSON data into an array of Scala objects

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.4, “How to parse JSON data into an array of Scala objects.”


You have a JSON string that represents an array of objects, and you need to deserialize it into objects you can use in your Scala application.

Ruby - How to sort an array of objects by one field

Sorting an array of objects by one column in the object (class) is pretty simple with Ruby. Here's a quick demo of how I just did this when working on sorting the rows in a CSV file in a simple Ruby script.

Define the class

Step 1 in this is defining my class. So, here's the definition of my Ruby Person class:

A Java web service client that gets a list of objects

I just solved a problem with a Java web service client I've been working on. I've been trying to read a Java web service that was created with Apache Axis2, and it has methods that can return an array or List of User objects. I couldn't find any examples on the Axis2 web site that showed how to get an array or List from a web service client, but I finally find the solution by digging around a little.

In this post I'll provide some sample Java source code that shows what I did to solve this problem.

Java StringBuffer versus String: When to use StringBuffer

The most common reason to use a StringBuffer instead of a String in your Java programs is when you need to make a lot of changes to a string of characters. For instance, a lot of times you’ll be creating a string of characters that is growing, as shown in this sample example program: