set

How to create a mutable Set in Scala

Scala Set FAQ: How do I create a mutable Set in Scala?

To create a mutable set in Scala, first determine the type of set you want. You do this because the mutable Set is actually a trait, and you need to determine which concrete implementation you want.

For instance, if you want a SortedSet of String, define it like this:

val names = scala.collection.mutable.SortedSet[String]()

Then you can add elements to the set later like this:

Getting the union, intersection, and difference of Scala sets

A cool thing about Scala sets -- and some other Scala collections -- is that you can easily determine the union, intersection, and difference between two sets. The following examples demonstrate how the methods work. First, we create two sets that have a slight overlap:

scala> val low = 1 to 5 toSet
low: scala.collection.immutable.Set[Int] = Set(5, 1, 2, 3, 4)

scala> val medium = (3 to 7).toSet
medium: scala.collection.immutable.Set[Int] = Set(5, 6, 7, 3, 4)

Now we exercise the methods. First, the union:

Java/Swing UIManager default values

As I'm preparing a different Java Swing tutorial, I thought I'd share a test class I just created to look at the default entries from the Java UIManager class.

Here's the source code for my Java class that prints all the Java Entry objects from the UIManager class. As you can see, I call the getLookAndFeelDefaults method of that class, and then call the entrySet method of that class to get all the default entries:

Perl CGI cookies - How to get and set cookies in Perl CGI programs

In Part 1 of this series, we provided some background information about cookies, discussing the problem of state maintenance in web applications. We discussed how cookies can help solve this problem, and outlined the drawbacks and limitations of cookies. We even discussed a few examples of how you might use cookies in a customizable web site or e-commerce site.

How do I set environment variables in Perl programs?

Perl environment FAQ: How do I set environment variables in Perl programs?

In several other articles, we've demonstrated how you can access the value of environment variables from your Perl programs. For example, to determine the setting of your "PATH" environment variable, you can just do something like this:

$path = $ENV{'PATH'};

As you may remember, %ENV is a special hash in Perl that contains the value of all your environment variables.

Setting the Drupal front page node

Drupal front page FAQ: How do I make a Drupal page (node) the front page of my Drupal website?

Drupal front page approaches

There are several ways to control the content of your Drupal front page, but if you just want to use a Drupal node as the front page of your site, you can set this on the Site Information admin page.

iPhone song rating - How to set a song rating on your iPod or iPhone

iPhone songs FAQ: Can I set or change the rating of an iTunes song on my iPhone or iPod?

Wow, I'm such an iPod/iPhone/Itunes dummy, I didn't realize that I could change the rating of a song from my iPhone until I dug into it a little bit. Here's a quick look at how to change the iTunes song rating from your iPhone/iPod.

Setting/changing an iPhone/iPod song rating

You can set the iTunes song rating directly from your iPhone (or iPod) when the song is playing.

How to put an object on the request in a servlet

Many times when you're working with Java servlets and JSP's, you'll want to forward some piece of information from your servlet to your JSP without having to put that piece of information into the session. For instance, in many applications you may not have a user session, and in other cases where you do have a session, you may just not want to put a bunch of junk in there.

How to set the default input focus on a field in an HTML web form

When I create a web-based user interface I tend to be a fanatic about making sure that the first input field on a form gets input focus when the form is first displayed. It always drives me crazy when I go to a web form that requires text input, but the developer of the page hasn't taken the time to put the default focus in the first field of the form.

So ... after looking around at some HTML/JSF/Struts/JSP code I've written over the last few years, the following JSF example shows the most concise way I know of setting default input focus on an HTML form field:

Syndicate content