Identation fixed applying https://github.com/eugenp/tutorials/blob/master/eclipse/formatter.xml
This commit is contained in:
parent
db772047f4
commit
0f0908bc18
@ -6,35 +6,36 @@ import java.util.List;
|
|||||||
|
|
||||||
public class RemoveFromList {
|
public class RemoveFromList {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
List<String> sports = new ArrayList<>();
|
List<String> sports = new ArrayList<>();
|
||||||
sports.add("Football");
|
sports.add("Football");
|
||||||
sports.add("Basketball");
|
sports.add("Basketball");
|
||||||
sports.add("Baseball");
|
sports.add("Baseball");
|
||||||
sports.add("Boxing");
|
sports.add("Boxing");
|
||||||
sports.add("Cycling");
|
sports.add("Cycling");
|
||||||
|
|
||||||
System.out.println("List before removing: " + sports);
|
System.out.println("List before removing: " + sports);
|
||||||
|
|
||||||
// Remove with index
|
// Remove with index
|
||||||
sports.remove(1);
|
sports.remove(1);
|
||||||
|
|
||||||
// Remove with an element
|
// Remove with an element
|
||||||
sports.remove("Baseball");
|
sports.remove("Baseball");
|
||||||
|
|
||||||
// Iterator remove method
|
// Iterator remove method
|
||||||
Iterator<String> iterator = sports.iterator();
|
Iterator<String> iterator = sports.iterator();
|
||||||
while(iterator.hasNext()){
|
while (iterator.hasNext()) {
|
||||||
if(iterator.next().equals("Boxing")){
|
if (iterator.next().equals("Boxing")) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArrayList removeIf method (Java 8)
|
||||||
|
for (int i = 0; i < sports.size(); i++) {
|
||||||
|
sports.removeIf(p -> p.equals("Cycling"));
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("List after removing: " + sports);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrayList removeIf method (Java 8)
|
|
||||||
for(int i = 0; i < sports.size(); i++){
|
|
||||||
sports.removeIf(p -> p.equals("Cycling"));
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("List after removing: " + sports);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user