๐Ÿค– ์•Œ๊ณ ๋ฆฌ์ฆ˜

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฟ€ํŒ. ์ž๋ฐ”

ttoance 2022. 6. 27. 23:20

1. ๋””๋ฒ„๊น… ์‹œ ๋ฌธ๊ตฌ์™€ ๋ณ€์ˆ˜ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๊ณ  ์‹ถ์„๋•Œ 

System.out.printf("๋น„๊ต๋ฌธ ์ถœ๋ ฅ %d < %d || %d < %d",a,b,c,d);
System.out.printf("๋ฌธ์ž์—ด ์ถœ๋ ฅ %s",e);

 

2. ์ตœ์†Œ๊ฐ’, ์ตœ๋Œ€๊ฐ’ ๊ตฌํ• ๋•Œ 

int min = Integer.MAX_VALUE;
while (true) {
    ...
    min = Math.min(min, origin[currentX][currentY]);
    ...
}

return min;

 

3. ๋ฐฐ์—ด ์ถœ๋ ฅํ•  ๋•Œ 

import java.util.Arrays;

// 1์ฐจ์› ๋ฐฐ์—ด 
System.out.println(Arrays.toString(arr));

// 2์ฐจ์› ๋ฐฐ์—ด
System.out.println(Arrays.deepToString(arr));

 

4. hashmap ๊ด€๋ จ 

import java.util.HashMap;

static HashMap<String, String> relationMaps = new HashMap<String, String>();
static HashMap<String, Integer> payMaps = new HashMap<String, Integer>();
static HashMap<String, ArrayList<String>> listMaps = new HashMap<String, ArrayList<String>>();

// ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€ 
for (int i = 0; i < enrolls.length; i++) {
    relationMaps.put(enrolls[i], referrals[i]);
}

// ๋ฐ์ดํ„ฐ ์ˆ˜์ • 
payMaps.replace(seller, payMaps.get(seller) + sellerPaid);

 

5. string for loop 

 String s = "blog";
 
// charAt 
for (int i = 0; i < s.length(); i++) {
    System.out.print(s.charAt(i));
}

 // toCharArray
char[] chars = s.toCharArray();
for (char ch: chars) {
    System.out.print(ch);
}

 

6. stringbuilder

StringBuilder sb = new StringBuilder();
sb.append("1 ").append("2");

// string ์ถœ๋ ฅ 
String str = sb.toString();

 

7. stack

Stack<Integer> stack = new Stack<>();
stack.push(1);	// push
stack.pop();	// pop
stack.size();	// size 
stack.get(i);	// index ๋ฆฌํ„ด
๋ฐ˜์‘ํ˜•