, 정수 교체. 즉if arrayList.get(i).get(j) == 3
이면 2
등이되지만, 1
인 경우 1
인 경우에만 해당합니다. ARRAYLIST<ARRAYLIST<INTEGER>>
의 특정 열에서만 가능합니다.다차원 ArrayList를하고, 그렇지 않으면 당신은 그것에서 <code>1</code>을 빼기 이중 차원 <code>ArrayList<ArrayList<Integer>></code>을 통해 당신이 그것을두고 <code>1</code> 같다 모든 <code>Int</code>가는 최고의 <em>(또는 어쨌든, 정말)</em> 무엇
0
A
답변
4
삽을 만드십시오. 한 가지 방법 만 있습니다. 모든 행의 모든 열 반복 :
// example declaration only - initially all zeros until you set them.
// assumes nrows and ncols are initialized and declared elsewhere
int [][] matrix = new int[nrows][ncols];
for (int i = 0; i < matrix.length; ++i) {
for (int j = 0; j < matrix[i].length; ++j) {
// operate on the values here.
if (matrix[i][j] != 1) {
matrix[i][j] -= 1;
}
}
}
을 당신이 다음과 같습니다 목록의 목록을 가지고있는 경우에 :
List<List<Integer>> matrix = new ArrayList<List<Integer>>();
List<Integer> columnIdsToTransform = Arrays.asList({0, 4, 6 });
// You have to initialize the references; all are null right now.
for (List<Integer> row : matrix) {
for (int j = 0; j < row.size(); ++j) {
// operate on the values here.
value = row.get(j);
if (columnsIdsToTransform.contains(j) && (value != 1)) {
row.set(value-1, j);
}
}
}
UPDATE : 당신의 편집에
을 바탕으로, 당신 이 변환을 수행 할 배열 또는 열 목록을 추가해야합니다. 두 번째 스 니펫에 예제를 추가했습니다.
1
모든 값을 반복하고 조건문을 사용하여 true
건에서 연산을 수행하십시오.
for (int i=0;i<Arraylist.size();i++) {
for (int j=0;j<Arraylist[i].size();j++) {
if (arrayList.get(i).get(j) != 1)
arrayList.get(i).get(j) -= 1;
}
}
관련 문제
- 1. Heredoc <<< 또는 <<?
- 2. 에코 "<! <"가 "<! >"을 반환하는 이유는 무엇입니까?
- 3. 레일 - ...</p> <p>을
- 4. <script></script> 또는 <script />?
- 5. 내가 전체 <code><li></code>을 제거 버튼에 클릭 이벤트를 다음 HTML 코드</p> <pre><code><li><div><..><input type="submit" ...></div></li> </code></pre> <p>을 추가 대기 이미지
- 6. <input>마다 <label>을 사용해야합니까?
- 7. 2 개 n 번째 자식 블록</p> <pre><code><div><span></span><span></span><span></span> <div><span></span><span></span><span></span></div> </div> </code></pre> <p>다음 HTML을 감안할 때 N
- 8. 방법, <code>DO WITH PARA COMMANDS</code></p> <p>을 통해
- 9. 은 :</strong>과로 끝나는 : { "<strong>을 {
- 10. github add <<<<<<< HEAD
- 11. <td>을 다르게 조작하십시오. <tr> 님의
- 12. 어떻게 <strong><code>ArrayList</code></strong>에 <strong><code>2d string array</code></strong>을 변환하는 안드로이드
- 13. "<"을 "% lt;"로 대체하는 NSXML
- 14. <문자열, ArrayList를 <Users>> 또는 HashMap의 <문자열, HashSet의 <Users>>
- 15. 은 iTextSharp에게</p> <pre><code><table><tr><td><img src='images/my.jpg'/></td></tr><tr><td>some text</td></tr></table> </code></pre> <p>QUS pdf 파일의
- 16. <form> 안에 <form>을 삽입 하시겠습니까?
- 17. <p></p>을 다음과 같이 LibXmlParsing이
- 18. Wix : <Upgrade>을 <Fragment>
- 19. '<Ctrl> - <Tab>`을 Konsole에 어떻게 전달합니까?
- 20. <input> 및 <iframe>을 수직 정렬하는 방법은 <td> 안에 있습니까?
- 21. 왜 모듈러스 연산자가 필요합니까? 당신이 할</p> <pre><code>int Limit = Value % Range; </code></pre> <p>을 : 대신</p> <p>:
- 22. C#을 - <T>
- 23. Ctrl + C와 Ctrl + [?]의 차이점은 무엇입니까? <kbd>Ctrl 키</kbd> + <kbd>C</kbd> 및 <kbd>Ctrl 키</kbd> + <kbd>[</kbd>의 차이점은 무엇
- 24. JsonStore가 무작위로 <i>을 던졌습니다.</i>
- 25. 쉘 :</p> <pre><code>a a b </code></pre> <p>가 어떻게 <code>for i in $input; do</code> 같은 것을 쓰고 <code>input</code>에 <code>"a" "a b"</code>을 할당 할 수 있습니다 : 변수
- 26. Asp.net : <% # 또는 <%
- 27. 인라인 헬퍼 및 페이지 출력 - 방법?</p> <pre><code>@helper JsCss() { Html.Script("jquery/jquery-1.6.2", cdn: true) } </code></pre> <p>나는 나의 페이지에서 인라인 도우미 전화 :</p> <pre><code><head> @JsCss() </head> </code></pre> <p>을
- 28. <p>어떻게해야합니까?</p> <p>감사합니다.</p>
- 29. ..</p> <p>을 여기에 조금 문제가
- 30. jQuery : <option>을 <select>에 추가
죄송합니다. 내가 게시했을 때 분명히 뇌 정신이 있었기 때문에 duffymo가 질문을 편집했습니다. –