import java.util.Iterator;이 코드를 컴파일하고 실행하면 다음과 같이 됩니다.
import java.util.TreeSet;
public class search_element {
public static void main(String[] args) {
// TreeSet 생성
TreeSettset = new TreeSet ();
// TreeSet 채우기
tset.add("abc");
tset.add("bcd");
tset.add("cde");
tset.add("정의");
tset.add("efg");
문자열 e = "def";
// TreeSet에 특정 요소가 있는지 확인합니다
boolean exists = tset.contains(e);
System.out.println(e+"가 트리 세트에 있습니까? "+존재);
문자열 e2 = "eee";
존재 = tset.contains(e2);
System.out.println(e2+"가 트리 세트에 있습니까? "+존재);
반복자<문자열> 반복자 = tset.iterator();
// 엘리먼트 검색 및 equals
while (iterator.hasNext()){
String obj = iterator.next();
if(obj.equals(e))
System.out.println(""개체 "+e+"가 목록에 있습니다.");
}
}
}
def가 트리셋에 있습니까? trueReferences:
eee가 트리 세트에 있습니까? false
def 객체가 목록에 있습니다
Please disable your ad blocker and refresh the window to use this website.