Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package CONTROLLER; import MODEL.Categoria; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.json.simple.JSONArray; import org.json.simple.JSONObject; /** * * @author dinho */ public class TProcessamentoCategoria implements Runnable { private ArrayList<Categoria> categorias = new ArrayList<>(); private JSONArray jsonArray; public TProcessamentoCategoria(JSONArray jsonArray) { this.jsonArray = jsonArray; } public ArrayList<Categoria> getRun() { return categorias; } @Override public void run() { ArrayList<String> auxCategoria = new ArrayList<>(); Iterator iteratorCategoria = jsonArray.iterator(); while (iteratorCategoria.hasNext()) { JSONObject objetoCategoria = (JSONObject) iteratorCategoria.next(); String categoria = (String) objetoCategoria.get("category"); auxCategoria.add(categoria); } Set<String> setCategoria = new HashSet<>(); for (String a : auxCategoria) { setCategoria.add(a); } Iterator<String> iCat = setCategoria.iterator(); int idCat = 0; while (iCat.hasNext()) { Categoria auxCat = new Categoria(); auxCat.setId(idCat); auxCat.setNome(iCat.next()); categorias.add(auxCat); idCat++; } } }