0

error: incompatible types: Object cannot be converted to String

import java.util.*; 
import java.io.*;

public class ArrayToCollection{
    public static void main(String args[])throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("How many elements you want to add to the array: ");
        int n = Integer.parseInt(in.readLine());
        String[] name = new String[n];
        for(int i = 0; i < n; i++){
            name[i] = in.readLine();
        }
        List list = Arrays.asList(name); 
        System.out.println();
        for(String li: list){
            String str = li;
            System.out.print(str + " ");
       }
    }
}

How to fix this error? How to convert an object to string? ........................................................ ........................................................

UserBlanko
  • 202
  • 2
  • 12
jiqe
  • 1
  • 5

0 Answers0