4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Java】文字列を一文字ずつ切り出しする方法

Posted at

一文字ずつ切り出す方法を簡単にまとめておきます。

##ソースコード例

class Main{
public static void main(String[] args) {

    //切り出しする文字列
    String text = "abcde";
    
    char[] work = new char[text.length()];

    for(int i = 0; i < text.length(); i++){
            work[i] = text.charAt(i);

            //切り出した文字列を一文字ずつ出力
            System.out.println(work[i]);
        	}
	}
}

##出力結果

a
b
c
d
e

この他にsubstringを使う方法などもあります。

4
2
3

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?