 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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"]
Advertisements
 