ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/JAVA

[JAVA] charAt() ๋ฉ”์†Œ๋“œ

NaNaRin๐Ÿ™ƒ 2021. 1. 6. 18:12

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#charAt(int)

 

String (Java SE 15 & JDK 15)

All Implemented Interfaces: Serializable, CharSequence, Comparable , Constable, ConstantDesc public final class String extends Object implements Serializable, Comparable , CharSequence, Constable, ConstantDesc The String class represents character strings.

docs.oracle.com


 

java.lang.String.charAt(int)

 

public char charAt(int index)

 

๋ฌธ์ž์—ด์—์„œ ํŠน์ • ์ธ๋ฑ์Šค์— ์œ„์น˜ํ•˜๋Š” ๋ฌธ์ž๋ฅผ ๋ฐ˜ํ™˜

๋ฌธ์ž์—ด ๋‚ด์˜ ๋ฌธ์ž๋Š” ์™ผ์ชฝ์—์„œ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ˆœ๋ฒˆ์ด ๋งค๊ฒจ์ง. ์ฒซ๋ฒˆ์งธ ๋ฌธ์ž์˜ ์ˆœ๋ฒˆ์€ 0.

 

๋งค๊ฐœ๋ณ€์ˆ˜ int :

0๊ณผ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด-1 ์‚ฌ์ด์˜ ์ •์ˆ˜๊ฐ’.

 

๋ฐ˜ํ™˜๊ฐ’ char :

์ง€์ •๋œ ์ธ๋ฑ์Šค์— ํ•ด๋‹นํ•˜๋Š” ์œ ๋‹ˆ์ฝ”๋“œ ๋‹จ์ผ๋ฌธ์ž๋ฅผ ๋ฐ˜ํ™˜

 

String.charAt(index)

 


์˜ˆ์ œ

public class CharAtEx {

	public static void main(String[] args) {
		String s = "A0B1C2D3E4";

		System.out.println(s.charAt(0));
		System.out.println(s.charAt(1));
		System.out.println(s.charAt(3));
		System.out.println(s.charAt(4));
		System.out.println(s.charAt(5));
		System.out.println(s.charAt(8));

	}
}

 

์ถœ๋ ฅ

A
0
1
C
2
E

 

 

์‚ฌ์šฉ ์˜ˆ : nanarin.tistory.com/2