「Java」コレクションLinkedListの要素を削除するコード

Javaコード
import java.util.LinkedList;
public class RemoveElementFromLinkedList {

public static void main(String[] args) {

// Create a LinkedList
LinkedList<String> lnkPa = new LinkedList<String>();

// Add elements to LinkedList
lnkPa.add(“Jquery");
lnkPa.add(“Objective-C");
lnkPa.add(“C言語");
lnkPa.add(“PHP");
lnkPa.add(“Java");

// Displaying Elements before replace
System.out.println(“LinkedList Elements:");
for(String str: lnkPa){
System.out.println(str);
}

// Removing 3rd element
Object e1 = lnkPa.remove(2);
System.out.println(“\nElement “+ e1+ " removed from the list\n");

// LinkedList elements after remove
System.out.println(“After removal:");
for(String str2: lnkPa){
System.out.println(str2);
}
}

}
実行結果
LinkedList Elements:
Jquery
Objective-C
C言語
PHP
Java

Element C言語 removed from the list

After removal:
Jquery
Objective-C
PHP
Java

Java

Posted by arkgame