Example usage for java.util ArrayList get

List of usage examples for java.util ArrayList get

Introduction

In this page you can find the example usage for java.util ArrayList get.

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    int totalElements = arrayList.size();
    for (int index = 0; index < totalElements; index++)
        System.out.println(arrayList.get(index));
}

From source file:fitmon.DietAPI.java

public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException,
        ParserConfigurationException, SAXException, IOException {
    DietAPI obj = new DietAPI();
    ArrayList<Food> foodList = new ArrayList<Food>();
    ArrayList<ArrayList<Food>> listOfFoodList = obj.searchFood("apple");
    for (int i = 0; i < listOfFoodList.size(); i++) {
        for (int j = 0; j < listOfFoodList.get(i).size(); j++) {
            foodList.add(listOfFoodList.get(i).get(j));
        }//from  w  w w. j  a v  a2s .  c  o  m
    }

}

From source file:MainClass.java

public static void main(String[] a) {
    ArrayList<Employee> emps = new ArrayList<Employee>();
    emps.add(new Employee("A", "G"));
    emps.add(new Employee("T", "A"));
    emps.add(new Employee("K", "J"));

    System.out.println(emps);//from   w ww. ja v  a2s .c  om

    Employee e = emps.get(1);
    e.setLastName("new");

    System.out.println(emps);
}

From source file:eurecom.constrained.devices.MainReasonSensorData.java

public static void main(String[] args) {
    //String sensor_data = WSUtils.queryWebServiceJSON(RASPBERRYPI_WEATHER_LUMINOSITY);
    String sensor_data = ReadFile.readContentFile(SENSOR_DATA_FILE);
    ConvertRaspberrySensorData converter = new ConvertRaspberrySensorData();
    Model model;/*w  w w. j a  v  a2 s  .  c o m*/
    try {
        model = converter.convertRaspberrySensorDataToRDF(sensor_data, M3_RULES_PATH);

        //load the M2M measurement
        M2MAppGeneric m2mappli = new M2MAppGeneric(model);

        //load domain specific datasets and ontologies
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, M3_ONTOLOGY_PATH);//no need
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, TRANSPORT_ONTOLOGY_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, TRANSPORT_DATASET_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, WEATHER_ONTOLOGY_PATH);
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, WEATHER_DATASET_PATH);

        //variable in the sparql query
        ArrayList<VariableSparql> var = new ArrayList<VariableSparql>();
        var.add(new VariableSparql("inferTypeUri", Var.NS_M3 + "WeatherLuminosity", false));
        var.add(new VariableSparql("typeRecommendedUri", Var.NS_TRANSPORT_ONTOLOGY + "SafetyDevice", false));//SafetyDevice

        Model inf = m2mappli.reasonWithJenaRules(LOR_FILE_PATH);//reasoner for jena rules //Var.LINKED_OPEN_RULES
        ExecuteSparqlGeneric reqSenml = new ExecuteSparqlGeneric(inf, SPARQL_QUERY_WEATHER_SAFETY_DEVICES_PATH);

        ArrayList<ResultSensorDataReasoning> resultAfterReasoning = reqSenml.getSelectResultAnsParseIt(var);
        for (int i = 0; i < resultAfterReasoning.size(); i++) {
            System.out.println(resultAfterReasoning.get(i).toString());
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.dakror.jagui.parser.NGuiParser.java

public static void main(String[] args) {
    try {/*from ww w  . j a  va 2 s .  co m*/
        DIR.mkdirs();
        if (!new File(DIR, "convert.exe").exists())
            Helper.copyInputStream(NGuiParser.class.getResourceAsStream("/res/convert.exe"),
                    new FileOutputStream(new File(DIR, "convert.exe")));

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        JFileChooser jfc = new JFileChooser(
                new File(NGuiParser.class.getProtectionDomain().getCodeSource().getLocation().toURI()));
        jfc.setMultiSelectionEnabled(false);
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setFileFilter(new FileNameExtensionFilter("Unity ngui Gui-Skin (*.guiskin)", "guiskin"));

        if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            p("Collecting GUIDs, Converting Resources");
            HashMap<String, File> guids = collectGUIDs(jfc.getCurrentDirectory());

            p("Parsing Guiskin file");
            String s = Helper.getFileContent(jfc.getSelectedFile());
            String[] lines = s.split("\n");
            ArrayList<String> l = new ArrayList<>(Arrays.asList(lines));
            String string = "";
            for (int i = 0; i < l.size(); i++)
                if (!l.get(i).startsWith("%") && !l.get(i).startsWith("---"))
                    string += l.get(i) + "\n";

            Yaml yaml = new Yaml();
            for (Iterator<Object> iter = yaml.loadAll(string).iterator(); iter.hasNext();) {
                JSONObject o = new JSONObject((Map<?, ?>) iter.next());
                p("Cconverting Guiskin");
                replaceGuidDeep(o, guids, jfc.getSelectedFile());
                p("Writing converted file");
                Helper.setFileContent(new File(jfc.getSelectedFile().getParentFile(),
                        jfc.getSelectedFile().getName() + ".json"), o.toString(4));
                p("DONE");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    // Build a vector of words to be sorted
    ArrayList list = new ArrayList();
    list.add("m");
    list.add("c2");
    list.add("e");
    list.add("c1");

    Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k++)
        keys[k] = collate.getCollationKey((String) list.get(k));

    Arrays.sort(keys);//from  w w w.  j a v a2  s. c  o  m

    for (int l = 0; l < keys.length; l++) {
        System.out.println(keys[l].getSourceString());
    }
}

From source file:TestMapObjInterface.java

public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println("Usage: MapObjInterfaceTest <filename> <vfs name> <CN address>");
        System.out.println("MapObjInterfaceTest is a unit test of mproxy's map_obj interface."
                + "  It expects as input a filename and a Parascale vfs name.");
        System.out.println(// w w w.java 2s . c om
                "It returns a listing of the chunks for the specified file" + " in the following format:");
        System.out.println();
        System.out.println("[1275] ChunkInfo: offset: 85563801600 length: 67108864 17 : "
                + "Filelength 85899345920 <0>StorageNodeInfo: nodeName: "
                + "atg-sn2 primar addr: 10.10.249.222 enabled: true up: true ");
        System.out.println();
        System.out.println("Callers may use this information to determine if the "
                + "map_obj interface is returning correct data.");
        System.exit(1);
    }
    try {
        if (args[args.length - 1].equals("auto")) {
            if (runTest(args[0], args[1], args[2])) {
                System.out.println("pass");
            } else {
                System.out.println("FAIL");
            }
        } else {
            ArrayList<String> output = getChunks(args[0], args[1], args[2]);
            if (!output.isEmpty()) {
                int i = 0;
                for (i = 0; i < output.size(); i++) {
                    System.out.println(output.get(i));
                }
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String args[]) {

    // create an empty array list
    ArrayList<StringBuilder> arrlist1 = new ArrayList<StringBuilder>();

    // use add for new value
    arrlist1.add(new StringBuilder("from java2s.com"));

    // using clone to affect the objects pointed to by the references.
    ArrayList arrlist2 = (ArrayList) arrlist1.clone();

    // appending the string
    StringBuilder strbuilder = arrlist1.get(0);
    strbuilder.append("tutorials");

    System.out.println(arrlist1);

    System.out.println(arrlist2);
}

From source file:MainClass.java

public static void main(String[] args) {
    ArrayList list = new ArrayList();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i));
    }/*from www .jav  a  2  s  .com*/
}

From source file:eurecom.constrained.devices.ReadZipFile.java

public static void main(String[] args) {
    ZipFile zipfile;//from   w ww  .j  a v a2s .com
    String sensor_data = ReadFile.readContentFile(SENSOR_DATA_FILE);
    ConvertRaspberrySensorData converter = new ConvertRaspberrySensorData();
    Model model;
    try {
        model = converter.convertRaspberrySensorDataToRDF(sensor_data, M3_RULES_PATH);

        M2MAppGeneric m2mappli = new M2MAppGeneric(model);

        //LOAD ONTOLOGIES AND DATASETS
        //ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, "./WAR/M3IoTApplicationTemplate/transport");
        //   ReadFile.enrichJenaModelOntologyDataset(m2mappli.model, "./WAR/M3IoTApplicationTemplate/weather");
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                "./WAR/M3IoTApplicationTemplate/transport-dataset");
        ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                "./WAR/M3IoTApplicationTemplate/weather-dataset");

        //EXECUTE SPARQL QUERY

        Model inf = m2mappli.reasonWithJenaRules("./WAR/M3IoTApplicationTemplate/LinkedOpenRules.txt");
        ExecuteSparqlGeneric reqSenml = new ExecuteSparqlGeneric(inf,
                "./WAR/M3IoTApplicationTemplate/weatherTransportSafetyDevice.sparql");

        ArrayList<ResultSensorDataReasoning> resultAfterReasoning = reqSenml.getSelectResultAnsParseIt(null);

        for (int i = 0; i < resultAfterReasoning.size(); i++) {
            System.out.println(resultAfterReasoning.get(i).toString());
        }

        //EXECUTE RULES

        //try {
        /*   zipfile = new ZipFile(ZIP_FILE_IOT_APPLI);
           File file = new File("./WAR/M3IoTApplicationTemplate");
           unzip(zipfile, file);*/

        for (int i = 0; i < FILE_TO_LOAD.size(); i++) {
            System.out.println(FILE_TO_LOAD.get(i));

            //if extension is sparql then execute sparql
            if (FILE_TO_LOAD.get(i).contains(".sparql")) {

            }

            // if extension is .txt then execute rules
            if (FILE_TO_LOAD.get(i).contains(".txt")) {

            }

            //otherwise load ontology and dataset
            else {
                ReadFile.enrichJenaModelOntologyDataset(m2mappli.model,
                        "./WAR/M3IoTApplicationTemplate/transport-dataset");
                // + "\\" +FILE_TO_LOAD.get(i)
                m2mappli.model.write(System.out);
            }

        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    /*} catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
    }*/

}