사랑해 마니마니

minsoo study 본문

카테고리 없음

minsoo study

분리불안증후군 2020. 5. 18. 00:31

String Char IndexOf

  • String.indexOf(String str) //없는 경우 -1 Return
  • String.indexOf(int ch)
  • Stirng.indexOf(int ch, int fromIndex)
  • String.indexOf(String str, int fromIndex)
  • cf. String.lastIndexOf // 끝에서 부터 검색함
  • char ch = String.charAt(int index)

 

String, Char Operation

  • char[] charArray = string.toCharArray();

String Operation (Replace, Substring) 

  • String.replace(CharSequnce target, CharSequence replacement)
  • String.replaceAll(String 정규표현식, String replacement) cf: 여러 문자 조합: |, escape: \\
  • String.replaceFirst
  • String.substring(beginIndex)
  • String.substring(beginIndex, endIndex) //endIndex 앞까지 자름
  • boolean boolean String.contains

StringBuilder 사용하기

  • .append
  • .toString

String CompareTo

Parsing하기

  • String.split(String regex)

matches

자료 변환

  • Integer integer = Integer.valueOf(int i)
  • Integer integer = Integer.valueOf(String s)
  • int integer = Integer.parseInt(String s); // try {  } catch (NumberFormatException e) { }

숫자를 문자로

  • String s = ""+integer;

Eliment 순서 바꾸기

  • Collections.swap(list, index i, index j);

문자, 숫자 체크

try {
	Integer.parseInt(s);
	return true;
} catch (NumberFormatException e) {
	return false;
}
  • Character.isDigit(char c) // 만약 c에 integer값이 들어갈 경우 ascii값으로 환산하여 계산하여 true, false 반환

 

if(Pattern.matches("[1-9]", ""+ch));

List Sorting

cf 비교하기 string.compareTo(s) // 같으면 0, 크면 +1, 작으면 -1

        Collections.sort(list, new Comparator<Student>() {

            @Override

            public int compare(Student s1, Student s2) {

                if (s1.getScore() < s2.getScore()) {

                    return -1;

                } else if (s1.getScore() > s2.getScore()) {

                    return 1;

                }

                return 0;

            }

        });

Recursive

public static int func(int n) {
	if (n == 0)
		return 0;
	else
		return n + func(n - 1);
}

Cube 90도 돌리기

  • cube[cube.length-inx-1][jnx];

기타 idea

  • Math.max(number1, number2);
  • 갯수 구하기는 map으로
  • 자릿수 구하기: int num = (int)(Math.log10.(inputData) +1);

문자 삭제하기

  • List<Character> alphabets = letters.stream() .filter(Character::isAlphabetic) .collect(Collectors.toList());
  • for (Iterator<Character> iter = letters.iterator(); iter.hasNext(); ) { Character letter = iter.next(); if (Character.isDigit(letter)) { iter.remove(); } }

대소문자 구분

  • Character.isUpperCase(s)
  • Character.isLowerCase(s)
  • Character.isDigit(s)
Comments