- import java.util.*;
- class ArraysDemo
- {
- public static void main(String[] args){
-
- }
- // 数组变字符串
- public static void ArraysToString(){
- String[] str = {"afdsa","sdaf","fdaf"};
- String str1 = Arrays.toString(str);
- System.out.println(str1);
- }
- //数组变List集合
- public static void aslistDemo(){
- String[] str = {"afdsa","sdaf","fdaf"};
- List<String> list = Arrays.asList(str);
- Iterator it = list.iterator();
- while(it.hasNext()){
- String str1 = (String)it.next();
- System.out.println(str1);
- }
- }
- //集合变数组
- public static void toArrayDemo(){
- List<String> list = new ArrayList<String>();
- list.add("hkds");
- list.add("lkjn");
- list.add("mfsi");
- list.add("oesj");
- String[] str = list.toArray(new String[list.size()]);
- System.out.println(Arrays.toString(str));
- }
- }
复制代码 |
|