本帖最后由 王琪 于 2014-3-3 01:04 编辑
- package dom;
- import java.util.*;
- import java.util.ArrayList;
- import java.util.ListIterator;
- public class Text {
- static void fun(char[] a){
-
- char []c={ '1','2' ,'3','4' ,'5' };
- a=c;
-
- }
- public static void main(String[]args){
- char []c={ 'A','B' ,'C','D' ,'E' };
- fun(c);
- for(char z:c){
- System.out.print(z);
- }
- }
- //最后输出'A','B' ,'C','D' ,'E' 但我想让他变成12345
- }
- 之前也问过但是还是不懂.
- 最后集合可以
- import java.util.*;
- import java.util.ArrayList;
- import java.util.ListIterator;
- public class Text2 {
- static void fun(ArrayList<font color="Red"><Character> a</font>){
- <font color="Red">ListIterator it1=a.listIterator();</font>
- char []c={ '1','2' ,'3','4' ,'5','6','7' };
- for(char s:c){
- if(it1.hasNext()){
- it1.next();
- <font color="DarkOrchid">it1.set(new Character(s));</font>
-
- }
- else{break;}
- }
- }
- public static void main(String[]args){
- ArrayList<Character> a=new ArrayList<Character>();
-
- char []c={ 'A','B' ,'C','D' ,'E' };
- for(char v:c){
- a.add(new Character(v));
- }
- <font color="Red">fun(a);</font>
- System.out.println(a);
- }
- }
复制代码 输出1234567
|