반응형
ArrayList의 특정 위치에서 요소를 어떻게 업데이트합니까? [복제]
이 질문에는 이미 답변이 있습니다.
ArrayList
10 String
초 중 하나 가 있습니다. 5
다른 String
값으로 인덱스 를 어떻게 업데이트 합니까?
하자 arrList
수 ArrayList
와 newValue
새를 String
, 그럼 그냥 할 :
arrList.set(5, newValue);
이것은 java api reference here 에서 찾을 수 있습니다 .
list.set(5,"newString");
arrList.set(5,newValue);
그리고 업데이트하고 싶다면이 줄도 추가하십시오.
youradapater.NotifyDataSetChanged();
import java.util.ArrayList;
import java.util.Iterator;
public class javaClass {
public static void main(String args[]) {
ArrayList<String> alstr = new ArrayList<>();
alstr.add("irfan");
alstr.add("yogesh");
alstr.add("kapil");
alstr.add("rajoria");
for(String str : alstr) {
System.out.println(str);
}
// update value here
alstr.set(3, "Ramveer");
System.out.println("with Iterator");
Iterator<String> itr = alstr.iterator();
while (itr.hasNext()) {
Object obj = itr.next();
System.out.println(obj);
}
}}
arrayList.set (location, newValue); location = 여기서는 삽입, newValue = 삽입하려는 새 요소입니다.
통지는 선택 사항이며 조건에 따라 다릅니다.
반응형
'Programing' 카테고리의 다른 글
HTTP 오류 403.14-금지-웹 서버가이 디렉토리의 내용을 나열하지 않도록 구성되었습니다. (0) | 2020.07.03 |
---|---|
각 지점과 마지막 개정 날짜를 Git에 나열 (0) | 2020.07.03 |
문자열에서 처음 3자를 제거 (0) | 2020.07.03 |
System.Web.Mvc가 참조 추가에없는 이유는 무엇입니까? (0) | 2020.07.03 |
ES6 맵 / 세트를 병합하는 가장 간단한 방법은 무엇입니까? (0) | 2020.07.03 |