'Java'에 해당하는 글 2건

toCharArray

Java 2013. 8. 18. 22:10

String str = "LOVE";

String strArr[]=str.toCharArray();

System.out.println(strArr[0]);

console =>

 L


toCharArray...

단어를 철자별로 잘라 배열에 저장해 준다.

'Java' 카테고리의 다른 글

Java substring  (0) 2012.11.11

WRITTEN BY
형때기
simple blog

,

Java substring

Java 2012. 11. 11. 23:09

개발을 하다보면 기본에 소홀 할때가 정말 많다

Asp 까지 병행 하다 보니 가끔 한가지 언어에만 몰두하면

Asp 문법을 Jsp 에 적용 하질 않나

함수를 가져다 쓸려고 하지 않나

가끔 상이한 문법을 써놓고 왜 안되지 하면서 

검색의 세계로 빠져든다

몇일던 경험해던 substring 이라는 놈..

ASP 의 left 라는 함수와 헷갈렸다

left(tmp,1) 이러질 않나 tmp.left(1) 이러질 않나

아직 운영하는 시스템의 소스만 분석 하는지라

잘 쓰지 않는 함수가 나올때면 삽질의 연속이다

이번기회에 확실히 정리해 보자 라는 마음에 블로그에 기입해 본다



뭐니 뭐니 해도 가장 빠른 법은 API 참조다

substring 메소드는 java.lang Package 의 String Class 에 있다

substring

public String substring(int beginIndex)
Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.

Examples:

 "unhappy".substring(2) returns "happy"
 "Harbison".substring(3) returns "bison"
 "emptiness".substring(9) returns "" (an empty string)
 

Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if beginIndex is negative or larger than the length of this String object.

두개가 있네....

첫번째꺼는 파라메터가 한개가 필요한데 해당 순번 부터 마지막 문자열까지 리턴 한다

기능은 예제를 보면 잘 알것 같고..

첫번째 문자가 0부터 시작한다는 점!!!

예외는 음수이거나 문자열 갯수보다 크면 발생 하는것 까지 정리!! 


substring

public String substring(int beginIndex,
                        int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Examples:

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"
 

Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex

두번째 꺼는 두개의 파라미터를 필요로 하는데

inclusive, 와 exclusive 가 중요!!!

두번째 인자는 포함되지 않는다!!!!

예제를 보면 잘 알수 있고

정리를 마치자 

아 공식 첫 포스팅 힘드네;;; 후압..


'Java' 카테고리의 다른 글

toCharArray  (0) 2013.08.18

WRITTEN BY
형때기
simple blog

,