Click here to Skip to main content
15,909,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.util.ArrayList;

public class ArrayListDemo {

    public static void main(String[] args) 
        {
            List<Integer> arrayList = new ArrayList<Integer>();

            for (int i = 1; i<5 ; i++)
                arrayList.add(i);
        }

        //Printing elememts
        System.out.println(arrayList);

        //Remove element at index 3
        arrayList.remove(3);

        //Displaying the ArrayList
        //after deletion 
        System.out.println(arrayList);

        //printing elememts one by one 
        for (int i = 0; i<arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+ " ");
        }



}


//errors showing
<pre>ArrayListDemo.java:14: error: <identifier> expected
        System.out.println(arrayList);
                          ^
ArrayListDemo.java:14: error: <identifier> expected
        System.out.println(arrayList);
                                    ^
ArrayListDemo.java:17: error: <identifier> expected
        arrayList.remove(3);
                        ^
ArrayListDemo.java:17: error: illegal start of type
        arrayList.remove(3);
                         ^
ArrayListDemo.java:21: error: <identifier> expected
        System.out.println(arrayList);
                          ^
ArrayListDemo.java:21: error: <identifier> expected
        System.out.println(arrayList);
                                    ^
ArrayListDemo.java:24: error: illegal start of type
        for (int i = 0; i<arrayList.size(); i++) {
        ^
ArrayListDemo.java:24: error: > expected
        for (int i = 0; i<arrayList.size(); i++) {
                                        ^
ArrayListDemo.java:24: error: <identifier> expected
        for (int i = 0; i<arrayList.size(); i++) {
                                             ^
9 errors


What I have tried:

I have tried to resolve the errors but the output is not generating because of errors.
Posted
Updated 10-Apr-22 2:26am
v2

I have no idea about Java...
See the comments in the code marked with 'HERE X.) <<<<< '

import java.util.ArrayList;

public class ArrayListDemo {

    public static void main(String[] args) 
        {
            // HERE A.)  <<<<<<<<<<<< 
            //List<Integer> arrayList = new ArrayList<Integer>();
            ArrayList<Integer> arrayList = new ArrayList<Integer>();

            for (int i = 1; i<5 ; i++)
                arrayList.add(i);
        // HERE B.)  <<<<<<<<<<<<  
        //}

        //Printing elememts
        System.out.println(arrayList);

        //Remove element at index 3
        arrayList.remove(3);

        //Displaying the ArrayList
        //after deletion 
        System.out.println(arrayList);

        //printing elememts one by one 
        for (int i = 0; i<arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+ " ");
        }

    // HERE C.)   <<<<<<<<<<<<  
    }
}
 
Share this answer
 
v3
Quote:
I have tried to resolve the errors but the output is not generating because of errors.

The positions of '{' and '}' matters. And a correct indentation highlight related problems.

Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
Java
import java.util.ArrayList;

public class ArrayListDemo {

  public static void main(String[] args) {
    List < Integer > arrayList = new ArrayList < Integer > ();

    for (int i = 1; i < 5; i++)
      arrayList.add(i);
  }

  //Printing elememts
  System.out.println(arrayList);

  //Remove element at index 3
  arrayList.remove(3);

  //Displaying the ArrayList
  //after deletion 
  System.out.println(arrayList);

  //printing elememts one by one 
  for (int i = 0; i < arrayList.size(); i++) {
    System.out.print(arrayList.get(i) + " ");
  }

}

Indentation style - Wikipedia[^]
https://codebeautify.org/javaviewer[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[^]
 
Share this answer
 
Comments
0x01AA 10-Apr-22 10:59am    
Quote: "Professional programmer's editors have this feature"
Professional programmers don't need such crutches :-)
Patrice T 10-Apr-22 11:59am    
May I reword : Professional editors for programmers ?
0x01AA 10-Apr-22 12:00pm    
Dont care too much about my comment ;)
Patrice T 10-Apr-22 12:10pm    
It is OK :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900