LoginSignup
7
7

More than 5 years have passed since last update.

Java 文字列から数値への変換&進数指定

Last updated at Posted at 2016-02-04

はじめに

事前に準備する外部ライブラリ等はありません。

実装例

サンプルでは、動作確認しやすいようにmainメソッドで実行できるようにしてあります。

StringToLong.java
/**
 *
 * @author tool-taro.com
 */
public class StringToLong {

    public static void main(String[] args) {

        //変換したい文字列
        String source = "21i3v9";
        //変換時の進数
        int radix = 36; //数値+アルファベット小文字の36進数

        //変換処理
        Long result = Long.parseLong(source, radix);
        //標準出力
        System.out.format("変換結果=%1$d", result);
    }
}

動作確認

$ javac StringToLong.java
$ java StringToLong
$ 変換結果=123456789

環境

  • 開発

    • Windows 10 Pro
    • JDK 1.8.0_112
    • NetBeans IDE 8.2
  • 動作検証

    • CentOS Linux release 7.2
    • JDK 1.8.0_112

Webツールも公開しています。
Web便利ツール@ツールタロウ

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7