Q:

Remove the object LinkedList

I have created a program regarding LinkedList and here is the code:
package consoleapplication;

import java.util.Scanner;
import java.util.LinkedList;

public class Index {

static int s, n ,e;

public static void main(String[] args) { 
        // LinkedList
        LinkedList k = new LinkedList();

        // input
        Scanner a = new Scanner(System.in);

        System.out.println("Size: ");
        s = a.nextInt();

        System.out.println("Element: ");
        e = a.nextInt();

        // process
        for (n = 0; n < s; n++) {
            k.add(n);
        }

        // output
        System.out.println("Index of " + e + k);
    }
}

Here is the output:
Size: 12
Element: 12
Index of 12[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

The program is running. But I want to remove one element. For example, I want to remove 0 or any number in the index of 12. How can I do that?

A:

you should use next methods
    k.remove();
    k.remove(Index);
    k.removeFirst();
    k.removeLast();

Here is a short example about it usage:
import java.util.Arrays;
import java.util.LinkedList;

public class Index {

    public static void main(String[] args) {

        // LinkedList

        LinkedList<Integer> k = new LinkedList<Integer>() {
            {
                addAll(Arrays.asList(new Integer[]{1, 2, 3, 4, 5, 6, 7}));
            }
        };

        System.out.println("Initial List:           " + k);
        k.remove(); //Retrieves and removes the head (first element) of this list.
        System.out.println("List after k.remove():  " + k);
        k.remove(2); //Removes the element at the specified position in this list.
        System.out.println("List after k.remove(2): " + k);
        k.removeFirst();//Removes and returns the first element from this list.
        System.out.println("List after k.removeFirst():" + k);
        k.removeLast();//Removes and returns the last element from this list.
        System.out.println("List after k.removeLast(): " + k);
    }
}

And output:
Initial List:           [1, 2, 3, 4, 5, 6, 7]
List after k.remove():  [2, 3, 4, 5, 6, 7]
List after k.remove(2): [2, 3, 5, 6, 7]
List after k.removeFirst():[3, 5, 6, 7]
List after k.removeLast(): [3, 5, 6]

