Blog Posts
- Home /
- Blog Posts
Set
- Java
- 2021년 6월 1일
Set은 자바의 Collection중에 객체를 중복하지 않고 하나만 저장하는 자료구조로 List와 다르게 저장순서(index)를 따로 저장하지 않기 때문에 이를 통해 접근할 수 없다. Set interface 제공 메서드 메서드 리턴 값 설명 add(E e) boolean 객체 추가성공하면 true addAll(Collection c) boolean 컬렉션을 추가하면 데이터들을 Set에 맞게 저장 remove(Object o) boolean 객체 삭제 contains(Object o) boolean 객체가 포함되었...
Read More제어문
- Golang
- 2021년 6월 1일
1. if문 제어문 중에 하나로 다른 언어들과 사용목적은 동일하며 if~else if~else 를 똑같이 지원한다. 1) 선언 방법 score := 56 if score > 80 { fmt.Println("A") } else if(score > 50) { //소괄호로 감쌌지만 not Error fmt.Println("B") } else { fmt.Println("C") } if true { fmt.Println("true") //조건이 bool이면 success } if 1 { fmt.Println("true") //bool이 아니면 error } Java나 c처럼 **()**로 조건문을 감싸지 않고 바로 조건문을 작성하면 되고 Java처...
Read More구조체
- Golang
- 2021년 5월 31일
여러 필드를 묶어서 사용하는 타입으로 C의 structure와 비슷하며, go에서는 별도의 클래스를 키워드를 제공하지 않지만 구조체를 이용해서 클래스를 정의할 수 있다. 1. 선언 /* type 이름 sturct{ ... 필드명 } */ type School struct{ Name string CntTeacher int } type Student struct { school School Name string score float64 } //Student형 변수 선언 var student Student student.Name = "홍길동" student.score = 87.1 struct을...
Read MorePermutation(순열)
- Algorithm
- 2021년 5월 28일
1. next_permutation c++에는 algorithm헤더에 매개변수의 배열/iterator의 다음 순열을 적용시켜 바뀌었다면 true/false를 반환해주는 메서드가 존재해서 이를 do~while문으로 쉽게 순열문제를 해결할 수 있다. 하지만, 자바는 존재하지 않기 때문에 다음과 같이 구현할 수 있다. public boolean next_permutation(int[] arr){ //뒤에서부터 탐색해서 내림차순이 깨...
Read MoreList를 Array로 Array를 List로 변환
- Java
- 2021년 5월 27일
List와 Array간의 변환은 기본적으로 for문을 이용하여 하나하나 바꾸어주면 변환이 가능하다. 하지만 for이 아닌 stream API를 이용해서 더 간편하게 바꿀 수 있는 방법을 정리한다. 1. List에서 Array로 변환 1) List -> Object[] List<Integer> integerList = new ArrayList<>(); List<String> stringList = new ArrayList<>(); Integer[] integerArr = integerList.toArray(new Integer[integerList.size()]); String[] stringArr = stringList.toArray(new String[stringList.size()]); Object[] objectArr = integerList.toArray(); List에서 Wrapper객체배열로 바꾸는 것은 Li...
Read More