Example usage for java.util ArrayList indexOf

List of usage examples for java.util ArrayList indexOf

Introduction

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

Prototype

public int indexOf(Object o) 

Source Link

Document

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Usage

From source file:Main.java

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

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

    System.out.println(arrayList.contains("2"));

    int index = arrayList.indexOf("4");
    if (index == -1)
        System.out.println("not contain 4");
    else//from w w  w  .  j av a 2  s.  c o  m
        System.out.println("4 at index :" + index);

    int lastIndex = arrayList.lastIndexOf("1");
    if (lastIndex == -1)
        System.out.println("not contain 1");
    else
        System.out.println("Last index :" + lastIndex);
}

From source file:Main.java

public static void main(String[] args) {

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

    arrlist.add("G");
    arrlist.add("E");
    arrlist.add("F");
    arrlist.add("M");
    arrlist.add("from java2s.com");

    System.out.println("Size of list: " + arrlist.size());

    System.out.println(arrlist);/*from w  w  w.  j  ava2s  .  co  m*/

    // retrieving the index of element "E"
    int retval = arrlist.indexOf("E");
    System.out.println("The element E is at index " + retval);
}

From source file:akori.AKORI.java

public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("esto es AKORI");

    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\";
    NAME = "mbauchile.png";
    // Extrar DOM tree

    Document doc = Jsoup.connect(URL).timeout(0).get();

    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    int xmax = driver.manage().window().getSize().width;
    int ymax = driver.manage().window().getSize().height;

    // Go to the URL page
    driver.get(URL);/*from   w  w w . j av  a2s. c  o  m*/

    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screen, new File(PATH + NAME));

    BufferedImage img = ImageIO.read(new File(PATH + NAME));
    //Graphics2D graph = img.createGraphics();

    BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graph1 = img.createGraphics();
    double[][] matrix = new double[ymax][xmax];
    BufferedReader in = new BufferedReader(new FileReader("et.txt"));
    String linea;
    double max = 0;
    graph1.drawImage(img, 0, 0, null);
    HashMap<String, Integer> lista = new HashMap<String, Integer>();
    int count = 0;
    for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) {
        String[] datos = linea.split(",");
        int x = (int) Double.parseDouble(datos[0]);
        int y = (int) Double.parseDouble(datos[2]);
        long time = Double.valueOf(datos[4]).longValue();
        if (x >= xmax || y >= ymax)
            continue;
        if (time < 691215)
            continue;
        if (time > 705648)
            break;
        if (lista.containsKey(x + "," + y))
            lista.put(x + "," + y, lista.get(x + "," + y) + 1);
        else
            lista.put(x + "," + y, 1);
        ++count;
    }
    System.out.println(count);
    in.close();
    Iterator iter = lista.entrySet().iterator();
    Map.Entry e;
    for (String key : lista.keySet()) {
        Integer i = lista.get(key);
        if (max < i)
            max = i;
    }
    System.out.println(max);
    max = 0;
    while (iter.hasNext()) {
        e = (Map.Entry) iter.next();
        String xy = (String) e.getKey();
        String[] datos = xy.split(",");
        int x = Integer.parseInt(datos[0]);
        int y = Integer.parseInt(datos[1]);
        matrix[y][x] += (int) e.getValue();
        double aux;
        if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) {
            max = aux;
        }
        //normalMatrix(matrix,x,y,20);
        if (matrix[y][x] > max)
            max = matrix[y][x];
    }
    int A, R, G, B, n;
    for (int i = 0; i < xmax; ++i) {
        for (int j = 0; j < ymax; ++j) {
            if (matrix[j][i] != 0) {
                n = (int) Math.round(matrix[j][i] * 100 / max);
                R = Math.round((255 * n) / 100);
                G = Math.round((255 * (100 - n)) / 100);
                B = 0;
                A = Math.round((255 * n) / 100);
                ;
                if (R > 255)
                    R = 255;
                if (R < 0)
                    R = 0;
                if (G > 255)
                    G = 255;
                if (G < 0)
                    G = 0;
                if (R < 50)
                    A = 0;
                graph1.setColor(new Color(R, G, B, A));
                graph1.fillOval(i, j, 1, 1);
            }
        }
    }
    //graph1.dispose();

    ImageIO.write(img, "png", new File("example.png"));
    System.out.println(max);

    graph1.setColor(Color.RED);
    // Extraer elementos
    Elements e1 = doc.body().getAllElements();
    int i = 1;
    ArrayList<String> tags = new ArrayList<String>();
    for (Element temp : e1) {

        if (tags.indexOf(temp.tagName()) == -1) {
            tags.add(temp.tagName());

            List<WebElement> query = driver.findElements(By.tagName(temp.tagName()));
            for (WebElement temp1 : query) {
                Point po = temp1.getLocation();
                Dimension d = temp1.getSize();
                if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0)
                    continue;
                System.out.println(i + " " + temp.nodeName());
                System.out.println("  x: " + po.x + " y: " + po.y);
                System.out.println("  width: " + d.width + " height: " + d.height);
                graph1.draw(new Rectangle(po.x, po.y, d.width, d.height));
                ++i;
            }
        }
    }

    graph1.dispose();
    ImageIO.write(img, "png", new File(PATH + NAME));

    driver.quit();

}

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));
    }//from www . j  av a 2s .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:Main.java

public static Date get(List<Date> otherDates, Date dateToApproach) {
    final TreeSet<Date> set = new TreeSet<Date>(otherDates);
    set.add(dateToApproach);/*from   ww  w  . ja  v  a 2 s .  co m*/
    final ArrayList<Date> list = new ArrayList<Date>(set);
    final int indexOf = list.indexOf(dateToApproach);
    if (indexOf == 0)
        return null;
    return list.get(indexOf - 1);
}

From source file:Main.java

public static void uniqe(int[] words, ArrayList<Integer> tempUniqueWords, ArrayList<Integer> tempCounts) {
    for (int i = 0; i < words.length; i++) {
        if (tempUniqueWords.contains(words[i])) {
            int index = tempUniqueWords.indexOf(words[i]);
            tempCounts.set(index, tempCounts.get(index) + 1);
        } else {/*from w w  w  .java 2  s .c  o  m*/
            tempUniqueWords.add(words[i]);
            tempCounts.add(1);
        }
    }
}

From source file:Main.java

public static int[] CountElmt(ArrayList<Integer> newScores1, ArrayList<Integer> scores) {
    int a[] = new int[scores.size()];
    for (int i = 0; i < scores.size(); i++) {
        a[i] = 0;/*w ww  .  j  a v a  2  s  .c  o  m*/
    }
    for (int i = 0; i < newScores1.size(); i++) {
        int value = newScores1.get(i);
        int pos = scores.indexOf(value);
        a[pos]++;
    }
    return a;
}

From source file:cooccurrence.emf.java

/**
 * Method to populate the apache matrix from cooccur hashmap
 *
 * @param matrixR//from   www . j a  v  a  2  s  . c o m
 * @param cooccur
 * @param rowStrings
 * @param colStrings
 */
private static void populateMatrixR(RealMatrix matrixR, HashMap<String, HashMap<String, Double>> cooccur,
        ArrayList<String> rowStrings, ArrayList<String> colStrings) {
    Iterator iter = cooccur.keySet().iterator();

    while (iter.hasNext()) {
        String row = iter.next().toString();
        int i = rowStrings.indexOf(row);
        HashMap<String, Double> inner = cooccur.get(row);
        for (String col : inner.keySet()) {
            int j = colStrings.indexOf(col);
            double val = inner.get(col);
            matrixR.setEntry(j, i, val); // each column in D represents the vector w-> d_w
        }
        iter.remove();
    }

}

From source file:Main.java

public static String evalConcat(Node n, String delimiter, XPathExpression... exprs)
        throws XPathExpressionException {
    ArrayList<String> results = new ArrayList<String>();
    for (XPathExpression expr : exprs) {
        results.add(orEmptyStr(expr, n));
    }//from  w w w. j  a  v  a  2 s.  c  o  m

    while (results.remove(""))
        ;

    String retn = "";

    for (String s : results) {
        retn += s;
        if (results.indexOf(s) != results.size() - 1) {
            retn += delimiter;
        }
    }

    return retn;
}

From source file:Main.java

/**
 * Returns the index of an element node from a provided list
 * @param actAllNodes//w ww .j a  v  a2s.  c om
 * @param element
 * @param exceptionList - a list of indexes that will not be taken in count
 * @return -1 if node not found in the list
 */
protected static int isNodePresent(NodeList actAllNodes, Element element, ArrayList<Integer> exceptionList) {
    int idx = -1;
    int tmpIdx = -1;
    try {
        String tmpElementName = element.getNodeName();

        for (int i = 0; i < actAllNodes.getLength(); i++) {
            if (actAllNodes.item(i).getNodeName().equals(tmpElementName)) {
                tmpIdx = i;
                if (exceptionList.indexOf(tmpIdx) == -1) {
                    idx = tmpIdx;
                    break;
                }
            }
        }
        return idx;
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}