0

I am creating a program that gets the seperate letters of a string entered by the user. I want to store my char information in a arraylist, but I am having some issues. Here is my code:

import java.util.*;

    public class Main {

        public static void main(String[] args) {

        String input, output;
        List<Character> characters = new ArrayList<Character>();

        Scanner scanner = new Scanner(System.in);

        System.out.print("Please type sentace to encode: ");
        input = scanner.nextLine();

        for(int i = 0; i < input.length(); i++) {
            characters.add(input.charAt(i)); 
        }
    }

}

I have already searched to forums, as I originally put char instead of Character, but now I am getting an error and eclipse wants me to change the jdk to v1.5. What is the issue?

5
  • "I am having some issues". What issues? Show os the stacktrace of the error. Commented Aug 4, 2014 at 7:42
  • what is your java version? Commented Aug 4, 2014 at 7:44
  • By the way, here is the error:- Syntax error, parameterized types are only available if source level is 1.5 or greater Commented Aug 4, 2014 at 7:46
  • @tomtomy8 r u sure u r using Java 8. Commented Aug 4, 2014 at 7:49
  • Have a look: dropbox.com/s/zr4dca2rxnzm322/Capture01.PNG Commented Aug 4, 2014 at 7:54

1 Answer 1

1

Replace

List<Character> characters = new ArrayList<Character>();

with diamond operator

List<Character> characters = new ArrayList<>();

Eclipse modifications:

From the menu bar: Project -> Properties -> Java Compiler

Enable project specific settings (checked) Uncheck "use Compliance from execution environment '.... Select the desired "compiler compliance level"

That will allow you to compile "1.5" code using a "1.6" JDK.

If you want to acutally use a 1.5 JDK to produce "1.5" compliant code, then install a suitable 1.5 JDK and tell eclipse where it is installed via:

Window -> preferences -> Installed JREs

And then go back to your project

Project -> properties -> Java Build Path -> libraries

remove the 1.6 system libaries, and: add library... -> JRE System LIbrary -> Alternate JRE -> The JRE you want.

Verify that the correct JRE is on the project's build path, save everything, and enjoy!

Sign up to request clarification or add additional context in comments.

1 Comment

All I'm getting is this: Multiple markers at this line - Syntax error, parameterized types are only available if source level is 1.5 or greater - '<>' operator is not allowed for source level below 1.7 - Incorrect number of arguments for type ArrayList<E>; it cannot be parameterized with arguments <>

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.