Java

    Set 에 대하여

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 HashSet set=new HashSet(); set.add(1); //추가 set.remove(1); //삭제 set.clear(); //비우기 set.contains(1); //해당 값 포함하는지 확인 set.size(); //크기 구하기 set.isEmpty(); //비어있는지 확인 Iterator it=set.iterator(); //iterator로 값 while(it.hasNext()){ int value=it.next(); sout(value); //1 } for(Integer tmp:set){ system.out.println(tmp); } //이것도 된다. //set에다가 새로운 set합칠 때에 사용 ..

    Java 조합과 순열

    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 30 31 32 public class test{ public static void main(String[] args) { int[] arr = {1, 3, 5, 7, 9}; boolean[] visit = new boolean[5]; combination(visit, 5, 3, 0, arr); } private static void combination(boolean[] visit, int n, int r, int start, int[] arr) { if (r == 0) { for (int i = 0; i

    2020.04.08 자바 훑기 (String 클래스, StringBuilder 클래스, 각종 Collection)

    2020.04.08 자바 훑기 (String 클래스, StringBuilder 클래스, 각종 Collection)

    지금까지 C,C++,Python 만 주구장창 이용해왔었고, 코딩문제도 C++ 로 풀곤 하였었는데, 이제 자바 기반의 프로그램을 할 것이기 때문에 자바와 친해지고 코딩문제도 자바로 푸는 것이 도움이 될 것이라고 생각해서 자바 언어를 다시 공부한다. String 클래스에 대해. String str1=new String("abc"); String str2=new String("abc"); str1.equals(str2) ==> 같다. String str1="wow"; String str2="wow"; 같은 인스턴스를 참조한다. 위의 new 는 그렇지 않다. String str1="Coffee"; String str2="Bread"; String str3=str1.concat(str2); str3 ==> Cof..