- 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
How to remove a specific element from a JSON Array in Java?
You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.
Example
import org.json.JSONArray; public class RemoveFromJsonArray { public static void main(String args[]) throws Exception { String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"}; JSONArray jsArray = new JSONArray(); for (int i=0; i < myArray.length; i++) { jsArray.put(myArray[i]); } System.out.println(jsArray); jsArray.remove(3); System.out.println("After deleting ::"+jsArray); } }
Output
["JavaFX","HBase","JOGL","WebGL"] After deleting ::["JavaFX","HBase","JOGL"]
- Related Articles
- How to remove Specific Element from a Swift Array?
- How to remove a specific element from array in MongoDB?
- Remove a specific element from a LinkedList in Java
- How to remove an element from an array in Java
- Remove duplicate element in a Java array.
- How to remove an element from a Java List?
- How to delete/remove an element from a C# array?
- How to print data of specific element from an array in java?
- How to remove element in a MongoDB array?
- How can I remove a specific item from an array in JavaScript
- How to remove element from ArrayList in Java?
- How can I remove a specific item from an array JavaScript?
- How to remove an element from a doubly-nested array in a MongoDB document?
- Remove an element from a Queue in Java
- Remove an element from a Stack in Java

Advertisements