- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Removal of negative numbers from an array in Java
Following program shows how to remove negative numbers from an array.
Example
import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Tester { public static void main(String[] args) { List<Integer> objArray = new ArrayList<Integer>(); objArray.clear(); objArray.add(2); objArray.add(-3); objArray.add(4); System.out.println("Array before removing an element "+objArray); Iterator<Integer> iterator = objArray.iterator(); while(iterator.hasNext()) { Integer next = iterator.next(); if(next < 0) { iterator.remove(); } } System.out.println("Array after removing an element"+objArray); } }
Output
Array before removing an element [ 2, -3, 4 ] Array after removing an element [ 2, 4 ]
- Related Articles
- Increment Negative and Decrement Positive Numbers by 1 in an Array in Java
- Maximum removal from array when removal time >= waiting time in C++
- Split an array of numbers and push positive numbers to JavaScript array and negative numbers to another?
- Make array numbers negative JavaScript
- LCM of an array of numbers in Java
- GCD of an array of numbers in java
- Find Count of Positive, Negative and Zero Elements in an Array in Java
- Check if Array is Free From 0 and Negative Number in Java
- C++ Program to find array after removal from maximum
- Can you pass the negative number as an Array size in Java?
- How to Remove Even Numbers from Array in Java?
- How to Remove Odd Numbers from Array in Java?
- Find count of positive and negative array elements in Java
- Finding even length numbers from an array in JavaScript
- Positive, negative and zeroes contribution of an array in JavaScript

Advertisements