Example usage for java.util ArrayList set

List of usage examples for java.util ArrayList set

Introduction

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

Prototype

public E set(int index, E element) 

Source Link

Document

Replaces the element at the specified position in this list with the specified element.

Usage

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> a = new ArrayList<>();
    a.add(1);/*w ww .  j  a va  2 s  .c o  m*/
    a.add(5);
    a.add(1);

    a.set(1, null);
    System.out.println(a.get(1));
    System.out.println(a);
}

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");

    arrayList.set(1, "REPLACED ELEMENT");
    for (String str : arrayList) {
        System.out.println(str);//from www.  j a  va 2s. com
    }
}

From source file:Main.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.clear();// w w w  . jav a  2  s.co  m
    nums.add("One");
    nums.add("Two");
    nums.add("Three");

    System.out.println(nums);
    nums.set(0, "Uno");
    nums.set(1, "Dos");
    nums.set(2, "Tres");
    System.out.println(nums);
}

From source file:Main.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.clear();//w  w  w  . j av  a  2s  .  co m
    nums.add("One");
    nums.add("Two");
    nums.add("Three");

    System.out.println(nums);
    nums.set(0, "Uno");
    nums.set(1, "Dos");
    nums.set(2, "java2s.com");
    System.out.println(nums);
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(1);/*from w w  w.j  av  a  2  s . c  o  m*/
    arrlist.add(2);
    arrlist.add(2);
    arrlist.add(2);

    System.out.println(arrlist);

    // change element to 55 at 3rd position
    arrlist.set(2, 55);

    System.out.println(arrlist);
}

From source file:ArrayListExample.java

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

    al.add(new Integer(1));
    al.add(new Integer(2));
    al.add(new Integer(3));
    al.add(new Integer(4));
    al.add(new Integer(5));
    al.add(new Integer(6));
    al.add(new Integer(7));
    al.add(new Integer(8));
    al.add(new Integer(9));
    al.add(new Integer(10));

    al.set(5, new Integer(66));

    for (Iterator i = al.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }/*from  ww w .  j a  v a2s .  c om*/
}

From source file:MainClass.java

public static void main(String[] args) {
    ArrayList myList = new ArrayList(5);
    for (int i = 0; i < 5; i++) {
        myList.add(new Integer(i));
    }/* w  ww  .j  a  v a2  s . c  om*/
    System.out.println("List contains " + myList.size() + " elements");

    Integer int2 = new Integer(2);
    System.out.println("List contains Integer(2): " + myList.contains(int2));
    System.out.println("Integer(2) is at index " + myList.indexOf(int2));

    myList.set(2, new Integer(99));
    System.out.println("Get element at index 2: " + myList.get(2));

    myList.ensureCapacity(15);
    for (int i = 10; i < 15; i++) {
        myList.add(new Integer(i));
    }

    myList.subList(10, 15).clear();
    myList.trimToSize();

    System.out.println(myList);
}

From source file:Anaphora_Resolution.ParseAllXMLDocuments.java

public static void main(String[] args)
        throws IOException, SAXException, ParserConfigurationException, TransformerException {
    //      File dataFolder = new File("DataToPort");
    //      File[] documents;
    String grammar = "grammar/englishPCFG.ser.gz";
    String[] options = { "-maxLength", "100", "-retainTmpSubcategories" };
    //LexicalizedParser lp =  new LexicalizedParser(grammar, options);
    LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
    ////w  w w.  ja va 2 s .  c  o  m
    //      if (dataFolder.isDirectory()) {
    //          documents = dataFolder.listFiles();
    //      } else {
    //          documents = new File[] {dataFolder};
    //      }
    //      int currfile = 0;
    //      int totfiles = documents.length;
    //      for (File paper : documents) {
    //          currfile++;
    //          if (paper.getName().equals(".DS_Store")||paper.getName().equals(".xml")) {
    //              currfile--;
    //              totfiles--;
    //              continue;
    //          }
    //          System.out.println("Working on "+paper.getName()+" (file "+currfile+" out of "+totfiles+").");
    //
    //          DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); // This is for XML
    //          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    //          Document doc = docBuilder.parse(paper.getAbsolutePath());
    //
    //          NodeList textlist = doc.getElementsByTagName("text");
    //          for(int i=0; i < textlist.getLength(); i++) {
    //              Node currentnode = textlist.item(i);
    //              String wholetext = textlist.item(i).getTextContent();
    String wholetext = "How about other changes for example the ways of doing the work and \n" + "\n"
            + "Iwould say security has , there 's more pressure put on people now than there used to be because obviously , especially after Locherbie , they tightened up on security and there 's a lot more pressure now especially from the ETR and stuff like that \n"
            + "People do n't feel valued any more , they feel  I do n't know I think they feel that nobody cares about them really anyway \n";

    //System.out.println(wholetext);
    //Iterable<List<? extends HasWord>> sentences;

    ArrayList<Tree> parseTrees = new ArrayList<Tree>();
    String asd = "";
    int j = 0;
    StringReader stringreader = new StringReader(wholetext);
    DocumentPreprocessor dp = new DocumentPreprocessor(stringreader);
    @SuppressWarnings("rawtypes")
    ArrayList<List> sentences = preprocess(dp);
    for (List sentence : sentences) {
        parseTrees.add(lp.apply(sentence)); // Parsing a new sentence and adding it to the parsed tree
        ArrayList<Tree> PronounsList = findPronouns(parseTrees.get(j)); // Locating all pronouns to resolve in the sentence
        Tree corefedTree;
        for (Tree pronounTree : PronounsList) {
            parseTrees.set(parseTrees.size() - 1, HobbsResolve(pronounTree, parseTrees)); // Resolving the coref and modifying the tree for each pronoun
        }
        StringWriter strwr = new StringWriter();
        PrintWriter prwr = new PrintWriter(strwr);
        TreePrint tp = new TreePrint("penn");
        tp.printTree(parseTrees.get(j), prwr);
        prwr.flush();
        asd += strwr.toString();
        j++;
    }
    String armando = "";
    for (Tree sentence : parseTrees) {
        for (Tree leaf : Trees.leaves(sentence))
            armando += leaf + " ";
    }
    System.out.println(wholetext);

    System.out.println();
    System.out.println("......");
    System.out.println(armando);
    System.out.println("All done.");
    //              currentnode.setTextContent(asd);
    //          }
    //          TransformerFactory transformerFactory = TransformerFactory.newInstance();
    //          Transformer transformer = transformerFactory.newTransformer();
    //          DOMSource source = new DOMSource(doc);
    //          StreamResult result = new StreamResult(paper);
    //          transformer.transform(source, result);
    //
    //          System.out.println("Done");
    //      }
}

From source file:Main.java

/**
 * It removes the first character of all the elements of the input ArrayList<String>
 * @param ar input array to be modified//from   w  w w . jav a 2s . c  o  m
 * @return the input array without the first character '/t'
 */
public static ArrayList<String> extractT(ArrayList<String> ar) {
    for (int i = 0; i < ar.size(); i++) {
        ar.set(i, ar.get(i).substring(1));
    }

    return ar;
}

From source file:Main.java

public static ArrayList<Integer> resetIncrementalList(ArrayList<Integer> list) {
    for (int i = 0; i < list.size(); i++) {
        if (i >= 2) {
            list.set(i, list.get(i) + list.get(i - 2));
        }//from  w w  w . ja v a 2  s.co  m
    }
    return list;
}