1

New to JAVA

I have this input and this output/

import java.util.List;

input:public class Solution{ List<Integer> lenght(List<Character> inputList){ body of method}}

expected output: [9,7,8]

My syntax for processing it/

List<Integer> lenghts = new ArrayList();

it says error can't find symbol for the line above. My syntax is wrong (I think it's out dated, from an old tutorial)

Can someone please tell me the correct syntax for the the variable to the input and out put. Thank you.

10
  • Do you have any import declarations at the top of your code? Commented Aug 4, 2020 at 6:18
  • yes/ import java.util.List; Commented Aug 4, 2020 at 6:18
  • I hope that's actually java.util.List - small j for Java, capital L for List. You'll also need java.util.ArrayList. Commented Aug 4, 2020 at 6:19
  • or simple import java.util.* Commented Aug 4, 2020 at 6:20
  • 2
    @emotionlessbananas Every time you use a * in an import, a kitten dies. javadude.com/posts/20040522-import-on-demand-is-evil Commented Aug 4, 2020 at 6:21

1 Answer 1

1

Simply use this thing List and ArrayList from java.util.*

import java.util.ArrayList;
import java.util.List;

List<Integer> lenght(List<Character> inputList)
{
    List<Integer> li = new ArrayList<Integer>();
    return li; 
}
Sign up to request clarification or add additional context in comments.

3 Comments

Do I have to import these two libraries? It only gave me (.List) in the question.
java.util.* or java.util.ArrayList java.util.List both are one and the same the only differenece is that if you import java.util.* all collection which are present under this library you can call without any extra import or error
Got it Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.