Bin/개발일지
2023-12-11, Today I Learned
개발바닥곰발바닥!!!
2023. 12. 11. 23:06
⭐Arraylist.contains() in Java
// creating an Empty Integer ArrayList
ArrayList<Integer> arr = new ArrayList<Integer>(4);
// using add() to initialize values
// [1, 2, 3, 4]
arr.add(1);
arr.add(2);
arr.add(3);
arr.add(4);
// use contains() to check if the element
// 2 exits or not
boolean ans = arr.contains(2);
if (ans)
System.out.println("The list contains 2");
else
System.out.println("The list does not contains 2");
⭐java 삼항연산자
int b = (5 < 4) ? 50 : 40;
int d = (a > b) ? a - b : b - a;