이 영역을 누르면 첫 페이지로 이동
Puter의 잡동사니 블로그의 첫 페이지로 이동

Puter의 잡동사니

페이지 맨 위로 올라가기

Puter의 잡동사니

잡다한 것이 한데 뒤섞인 곳

JAVA 06 배열/스트링/콜렉션

  • 2017.12.27 20:02
  • development
반응형

String을 사용 할 때는 == 사용금지

  • 대신에 equals()를 사용


1
2
3
4
5
6
7
8
9
10
11
12
13
String str1 = "abcde";
String str2 = "abcde";
if (str1 == str2) {                 //주소
    System.out.println("같다");
} else {
    System.out.println("다르다");
}
 
if (str1.equals(str2)) {            //값
    System.out.println("같다");
} else {
    System.out.println("다르다");
}
Colored by Color Scripter
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
String str3 = new String("abcde");
String str4 = new String("abcde");
if (str3 == str4) {                 //주소
    System.out.println("같다");
} else {
    System.out.println("다르다");
}
 
if (str3.equals(str4)) {            //값
    System.out.println("같다");
} else {
    System.out.println("다르다");
}
Colored by Color Scripter
cs
    
    
1
2
3
4
StringBuffer sb = new StringBuffer("abc");
System.out.println(sb);
sb.append("d"); 
System.out.println(sb);
cs
    
    
1
2
3
System.out.println(str1.charAt(0));
System.out.println(str1.length());
System.out.println(str1.substring(0, 2));
cs


1
2
3
4
5
6
7
8
String phon = "010-0000-7777";
String[] phonArr = phon.split("-");
 
for (int i = 0; i < phonArr.length; i++) {
    System.out.println(phonArr[i]);
}
 
System.out.println();
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
String phon1 = "021571577";
String[] phonArr1 = phon1.split("-");
 
for (int i = 0; i < phonArr1.length; i++) {
    System.out.println(phonArr1[i]);
}
 
String ch = phon1.replace("-", "");
System.out.println(ch);
 
String end = ch.substring(0, ch.length()-4);
System.out.println(end);
 
if(ch.substring(0, 2).equals("02")) {
    System.out.println(ch.substring(0, 2) + " " + end.substring(2) + " " + ch.substring(ch.length()-4, ch.length()));
} else {
    System.out.println(ch.substring(0, 3) + " " + end.substring(3) + " " + ch.substring(ch.length()-4, ch.length()));
}
Colored by Color Scripter
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int[][] score2 = new int[][] {
    {100, 90, 80},
    {80, 20, 30},
    {70, 90, 100},
    {30, 90, 60},
    {40, 100, 100}
};
 
System.out.println("번호\t총점"  );
System.out.println("=================");
for (int i = 0; i < score2.length; i++) {
    int sum2 = 0;
 
    System.out.print((i+1) + "\t");
    for (int j = 0; j < score2[i].length; j++) {
        sum2 += score2[i][j];
    }
    System.out.println(sum2);
}
Colored by Color Scripter
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int[][] score3 = new int[][] {
    {100, 90},
    {80},
    {70, 90, 100},
    {30, 90, 60},
    {40, 100}
};
 
System.out.println("번호\t평균"  );
System.out.println("=================");
for (int i = 0; i < score3.length; i++) {
    int sum2 = 0;
    double avg = 0.0;
 
    System.out.print((i+1) + "\t");
    for (int j = 0; j < score3[i].length; j++) {
        sum2 += score3[i][j];
    }
 
    avg = sum2/(double)score3[i].length;
    System.out.println(avg);
}
Colored by Color Scripter
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
 
ArrayList list = new ArrayList();
list.add(1);
list.add("2");
list.add("abd");
list.add(4);
list.add(4, "다섯번째");
 
 
for (int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i));
}
 
list.add("666");
 
for (int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i));
}
 
 
HashMap map = new HashMap();
 
map.put(1, "일");
map.put(2222, "이");
map.put("삼", 33333);
map.put("weight", 107.4);
 
System.out.println(map.get(1));
cs


반응형
저작자표시 비영리 동일조건 (새창열림)

'development' 카테고리의 다른 글

JAVA 08 객체지향 프로그래밍(2)  (0) 2017.12.27
JAVA 07 객체지향 프로그래밍(1)  (0) 2017.12.27
JAVA 05 배열  (0) 2017.12.27
JAVA 04 반복문(While)  (0) 2017.12.27
JAVA 03 반복문(for)  (0) 2017.12.27

댓글

이 글 공유하기

  • 구독하기

    구독하기

  • 카카오톡

    카카오톡

  • 라인

    라인

  • 트위터

    트위터

  • Facebook

    Facebook

  • 카카오스토리

    카카오스토리

  • 밴드

    밴드

  • 네이버 블로그

    네이버 블로그

  • Pocket

    Pocket

  • Evernote

    Evernote

다른 글

  • JAVA 08 객체지향 프로그래밍(2)

    JAVA 08 객체지향 프로그래밍(2)

    2017.12.27
  • JAVA 07 객체지향 프로그래밍(1)

    JAVA 07 객체지향 프로그래밍(1)

    2017.12.27
  • JAVA 05 배열

    JAVA 05 배열

    2017.12.27
  • JAVA 04 반복문(While)

    JAVA 04 반복문(While)

    2017.12.27
다른 글 더 둘러보기

정보

Puter의 잡동사니 블로그의 첫 페이지로 이동

Puter의 잡동사니

  • Puter의 잡동사니의 첫 페이지로 이동

검색

메뉴

  • ALL
  • #TAG

카테고리

  • Puter의 잡동사니 (164)
    • creation (5)
    • tagging (42)
    • product (63)
    • toy (18)
    • game (2)
    • clothes (4)
    • useful (3)
    • development (27)
반응형

정보

Puter의 Puter의 잡동사니

Puter의 잡동사니

Puter

블로그 구독하기

  • 구독하기
  • 네이버 이웃 맺기
  • RSS 피드

나의 외부 링크

  • kakao pay
  • 구글 Search Console
  • 구글 Analytics
  • 네이버 웹마스터 도구
  • 네이버 Analytics

방문자

  • 전체 방문자
  • 오늘
  • 어제
Powered by Tistory / Kakao. Copyright © Puter.

티스토리툴바