반응형
Array List의 특정 위치에서 요소를 업데이트하려면 어떻게 해야 합니까?
하나 있어.ArrayList
10분의 1의String
s. 인덱스를 업데이트하려면 어떻게 해야 합니까?5
다른 사람과 함께String
가치?
허락하다arrList
가 되다ArrayList
그리고.newValue
새것String
다음 작업을 수행합니다.
arrList.set(5, newValue);
이는 여기 Java API 참조에서 찾을 수 있습니다.
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=wnna 삽입 위치, newValue= 삽입할 새 요소.
notify 는 옵션이며 조건에 따라 달라집니다.
언급URL : https://stackoverflow.com/questions/4352885/how-do-i-update-the-element-at-a-certain-position-in-an-arraylist
반응형
'programing' 카테고리의 다른 글
Vuejs Axios 데이터가 표시되지 않음 (0) | 2022.08.02 |
---|---|
인증 토큰을 VueJ에 저장하는 모범 사례 (0) | 2022.08.02 |
vue js에서 루프(복수의 루프)가 완료된 후 메서드를 호출하려면 어떻게 해야 합니까? (0) | 2022.08.02 |
.vue 파일에서 여러 개체를 내보내는 방법 (0) | 2022.08.02 |
Vuex 저장소 상태가 정의되지 않았습니다. (0) | 2022.08.01 |