ArrayList.indexOf()

  • ArrayList의 indexOf()는 인자로 전달된 객체가 리스트에 존재한다면, 해당 객체의 인덱스를 리턴하고 없으면 -1을 리턴

String[] str = {"java", "c", "spring"};
ArrayList<String>  arr = new ArrayList<>(Arrays.asList(str));

System.out.println("indexOf(java) : " + arr.indexOf("java"));
System.out.println("indexOf(python) : " + arr.indexOf("python"));



indexOf(java) : 0
indexOf(python) : -1

 

  • 특정 문자에 대문자인지 소문자인지 확인

public class Test {
    public static void main(String[] args) {
        String s = "a";

        System.out.println(Character.isUpperCase(s.charAt(0)));
        System.out.println(Character.isLowerCase(s.charAt(0)));
    }


false
true
  • Math 클래스가 제공하는 pow() 메소드를 이용하면 된다.

  • Math.pow(대상숫자, 지수) 메소드는 전부 double형이다. 
public class Test {
    public static void main(String[] args) {

        double result = Math.pow(2, 3);
        System.out.println(result);

    }
}

8.0

대문자로 변경 (toUpperCase)

  • String클래스의 toUpperCase() 메서드를 사용

public class Test {
    public static void main(String[] args) {
        String str = "aaa";
        str = str.toUpperCase();
        System.out.println(str);
    }
}


AAA

 

소문자로 변경 (toLowerCase)

  • String클래스의 toLowerCase() 메서드를 사용

public class Test {
    public static void main(String[] args) {
        String str = "AAA";
        str = str.toLowerCase();
        System.out.println(str);
    }
}

aaa

+ Recent posts