Always get an error

Here is my project promtp:

Write the following method that splits a string into substrings using delimiter characters.
public static ArrayList split(String s, String delimiters);

Here are my errors:
Exception in thread “main” java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from List to ArrayList

    at Problem1.split(
    at Problem1.main(

Here is my code:

import java.util.*;
public class Problem1 {
   public static void main(String[] args){
       //make a scanner
       Scanner sc = new Scanner(;
       //prompt user to enter a string
       System.out.println("Enter a string: ");
       String s = sc.nextLine();
       //prompt user to enter delimiters
       System.out.println("Enter delimeters: ");
       String delimiters = sc.nextLine();

      split(s, delimiters);

   //split method
   public static ArrayList<String> split(String s, String delimiters){
        String[] array = s.split(delimiters);
        ArrayList<String> list = Arrays.asList(array);


no matter what I do I get the same error. Please help.

You might try looking here:

1 Like

So this tells me how to make an array into an arraylist, but I’m pretty sure I already did that?

String[] array = s.split(delimiters);
        ArrayList<String> list = Arrays.asList(array);

so uh, why the error?

Check the link again, your code is not in the same exact format… sample run of your program (so far):
Screen Shot 2020-11-06 at 6.43.37 PM

@arianna.pogact you have issue with array to ararylist conversion . Because Arrays.asList() method return List not Arraylist . I have improve your code as below . Please visit once these ways to convert array to list
How to convert array to arraylist

public static List split(String s, String delimiters){
String array = s.split(delimiters);
List list = Arrays.asList(array);
return list;

1 Like