반응형

2016/12/27 4

[Java 소스] 특정 문자나 문자열의 위치 확인 예

[Java 소스] 특정 문자나 문자열의 위치 확인 예 //특정 문자나 문자열의 위치 확인 예public class Program { public static void main(String[] args){ String str = new String("Hello world! low"); int index = 0; System.out.println("원본 문자열:"+str); index = str.indexOf('l'); System.out.print("l 문자 처음 발견:"); System.out.println(index); index = str.lastIndexOf('l'); System.out.print("l 문자 뒤쪽에서 처음 발견:"); System.out.println(index); index = ..

[Java 소스] 대소문자 구분 혹은 구분없이 문자열 비교

[Java 소스] 대소문자 구분 혹은 구분없이 문자열 비교 //대소문자 구분 혹은 구분없이 문자열 비교public class Program { public static void main(String[] args){ String str1 = new String("I am a boy."); String str2 = new String("i am a Boy."); if(str1.equalsIgnoreCase(str2)){ if(str1.equals(str2)){ System.out.println("같습니다."); } else{ System.out.println("대소문자만"); } } else{ System.out.println("서로 다릅니다."); } } } 실행 결과대소문자만 본문 [Java] 6.2.4..

[Java 소스] 전위나 후위에 부분 문자열이 있는지 확인하는 예

[Java 소스] 전위나 후위에 부분 문자열이 있는지 확인하는 예 //전위나 후위에 부분 문자열이 있는지 확인하는 예public class Program { public static void main(String[] args){ String str = "Here is ehpub.co.kr!"; String ex1 = "Here"; String ex2 = "kr!"; if(str.startsWith(ex1)) { System.out.println(ex1+"으로 시작"); } if(str.startsWith(ex2)) { System.out.println(ex2+"으로 시작"); } if(str.endsWith(ex1)) { System.out.println(ex1+"으로 끝남"); } if(str.ends..

[Java 소스] String 클래스 - 문자 시퀀스를 포함하는지 판별

[Java 소스] String 클래스 - 문자 시퀀스를 포함하는지 판별 //문자 시퀀스를 포함하는지 판별하는 예public class Program { public static void main(String[] args){ String s1 = "Here is ehpub.co.kr!"; CharSequence cs1 = "is"; CharSequence cs2 = "are"; System.out.println(s1.contains(cs1)); System.out.println(s1.contains(cs2)); } } 실행 결과true false 본문 [Java] 6.2.4 String 클래스 멤버 중에 판별에 사용하는 멤버 메서드학습에 도움이 되시면 ebook을 구입(판매가 3000원, ebook)하여 ..

반응형