alvin's blog

How to convert a Java String to a float

Java String/float FAQ: How do I convert a Java String to a float?

Converting a String to a float requires that you first convert the String to a Float object, then convert the Float object to a float data type (Float is an object, while float is a primitive data type).

An example of a simple program that performs this conversion is shown below:

A Java String to int conversion example

Java String to int FAQ: How do I convert a String to an int data type in Java?

Answer: You convert a String to an int using the parseInt method of the Java Integer class. The parseInt method converts the String to an int, and throws a NumberFormatException when the String can't be converted to an int type.

Let's take a look at two short examples.

The Tame Swing examples

Digging through my Mac laptop, I just found the old Tame Swing files laying around. These examples are a little old now, but I think they are great examples of the power of the Java Swing framework. Since they are hard to find on the internet I've gathered them into a little collection here.

Currently I just have the Java source code files there, but give me a couple of days and I'll see what I can do to get some of the examples running, and maybe include some screen shots there as well.


More Linux find command examples

The Linux find command is used to locate files and directories based on a wide variety of criteria. I'll try to cover the most common find examples here.

Basic find command examples

To find a file or directory named "foo" somewhere below your current directory use a find command like this:

find . -name foo

If the filename begins with "foo" but you can't remember the rest of it, you can use a wildcard character like this:

Linux mv command examples

The Linux mv command lets you move one or more files or directories. Since it's very similar to the cp command, I'll move through this post quickly.

Basic Linux mv examples

To rename a file currently named "foo" to a new file named "bar" just type:

mv foo bar

Although it's called the Linux mv command, it's commonly used to rename files.

To move a file named "foo" to the /tmp directory type:

Syndicate content