개발/Java
for문 사용 방법 중 두번째 방법
yunzema
2018. 6. 19. 16:18
반응형
List<EntityAnnotation> Texts = response.getResponses().get(0).getTextAnnotations();
for (EntityAnnotation Text : Texts) {
message.append(Text.getDescription());
message.append("\n");
}
for (EntityAnnotation Text : Texts) {
message.append(Text.getDescription());
message.append("\n");
}
Texts에 들어있는 값들을 하나씩 꺼내 Text에 대입한다는 의미이다. 간편하다!
일반적인 for문으로 쓴다면
for( int i = 0 ; i<Texts.size() ; i++){
Texts[i].getDescription();
}
이런식으로 사용했어야 한다. 코드가 간편해진다!
(물론 List뿐아니라 배열 등에 모두 사용가능)