List of usage examples for java.util ArrayList size
int size
To view the source code for java.util ArrayList size.
Click Source Link
From source file:Main.java
public static <T> int ceil(ArrayList<T> list, T key, Comparator<? super T> c) { if (c.compare(list.get(0), key) >= 0) { return 0; }//from w ww .j av a 2 s.c o m if (c.compare(list.get(list.size() - 1), key) < 0) { return -1; } int start = 0, end = list.size() - 1, res; T mid; while (start < end - 1) { mid = list.get((start + end) / 2); res = c.compare(mid, key); // System.out.println("res = " + res); // System.out.println("mid = " + mid); if (res >= 0) { end = (start + end) / 2; } else { start = (start + end) / 2; } // System.out.println("start = " + start); // System.out.println("end = "+ end); } res = c.compare(list.get(start), key); if (res < 0) { return end; } else { if (res == 0) { return start; } else { return -1; } } }
From source file:CB_Core.GCVote.GCVote.java
public static RatingData GetRating(String User, String password, String Waypoint) { ArrayList<String> waypoint = new ArrayList<String>(); waypoint.add(Waypoint);/*from w w w . j a va 2s . c om*/ ArrayList<RatingData> result = GetRating(User, password, waypoint); if (result == null || result.size() == 0) { return new RatingData(); } else { return result.get(0); } }
From source file:org.neo4j.nlp.examples.sentiment.main.java
private static boolean testOnText(String text, String label) { JsonObject jsonParam = new JsonObject(); jsonParam.add("text", new JsonPrimitive(text)); String jsonPayload = new Gson().toJson(jsonParam); String input = executePost("http://localhost:7474/service/graphify/classify", jsonPayload); System.out.println(input);/*from w w w. j ava 2 s . c o m*/ ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> hashMap = new HashMap<>(); try { hashMap = (Map<String, Object>) objectMapper.readValue(input, HashMap.class); } catch (IOException e) { e.printStackTrace(); } // Validate guess ArrayList classes = (ArrayList) hashMap.get("classes"); if (classes.size() > 0) { LinkedHashMap className = (LinkedHashMap) classes.stream().findFirst().get(); return className.get("class").equals(label); } else { return false; } }
From source file:Helpers.HelpersCSV.java
public static String joinArrayListAsEscapedString(ArrayList<String> arrayList) { ArrayList<String> escapedList = new ArrayList<String>(arrayList.size()); for (int i = 0; i < arrayList.size(); i++) { escapedList.add("\"" + arrayList.get(i) + "\""); }/* w w w. j av a 2 s .c o m*/ return StringUtils.join(escapedList, ','); }
From source file:key.secretkey.utils.PasswordStorage.java
/** * Gets the passwords (PasswordItem) in a directory * @param path the directory path/*from w w w .jav a 2s . c o m*/ * @return a list of password items */ public static ArrayList<PasswordItem> getPasswords(File path, File rootDir) { //We need to recover the passwords then parse the files ArrayList<File> passList = getFilesList(path); if (passList.size() == 0) return new ArrayList<PasswordItem>(); ArrayList<PasswordItem> passwordList = new ArrayList<PasswordItem>(); for (File file : passList) { if (file.isFile()) { passwordList.add(PasswordItem.newPassword(file.getName(), file, rootDir)); } else { // ignore .git directory if (file.getName().equals(".git")) continue; passwordList.add(PasswordItem.newCategory(file.getName(), file, rootDir)); } } sort(passwordList); return passwordList; }
From source file:Main.java
public static int[] randNum(int num, int min, int max) { ArrayList<Integer> list = new ArrayList<Integer>(); Random rand = new Random(); while (true) { int rm = (rand.nextInt(max - min) + min); if (!list.contains(rm)) { list.add(rm);/*w w w .j a va 2 s. c o m*/ if (list.size() >= num) break; } } int result[] = new int[num]; for (int i = 0; i < list.size(); i++) { result[i] = list.get(i); } return result; }
From source file:Main.java
public static ArrayList<Double> stringToDoubleListRemoved(String s, String delimeter, int[] fieldsToBeRemoved) { ArrayList<Double> ret = new ArrayList<Double>(); ArrayList<Double> allFields = stringToDoubleList(s, delimeter); HashSet<Integer> toBeRemoved = new HashSet<Integer>(); for (int i : fieldsToBeRemoved) toBeRemoved.add(i);// w w w .ja v a 2 s .c om for (int i = 0; i < allFields.size(); i++) { if (toBeRemoved.contains(i)) continue; ret.add(allFields.get(i)); } return ret; }
From source file:Main.java
/** * Change the extension of specified file.<br> * Usage :<br>/*from w ww. j a v a 2 s. c o m*/ * f.renameTo(MyFileUtility.reExtension(f, "jpg")) ;<br> * As we know ,File class is a dummy File , <br> * thus , you must follow the usage to change extension. * @param fin File input * @param newExtension newExtension without '.' * @return File with new extension */ public static File reExtension(File fin, String newExtension) { //Usage: f.renameTo(MyFileUtility.reExtension(f, "jpg")) ; StringTokenizer strTokener = new StringTokenizer(fin.getName(), "."); //For a file may has many '.' in its file name , we use a collection to stroe it. ArrayList<String> strVec = new ArrayList<String>(); while (strTokener.hasMoreTokens()) strVec.add(strTokener.nextToken()); String newName = ""; //Give up the original extension for (int i = 0; i != strVec.size() - 1; ++i) { newName += strVec.get(i); newName += "."; } newName += newExtension; return new File(fin.getParent() + "\\" + newName); }
From source file:com.espe.distribuidas.pmaldito.servidorbdd.operaciones.Archivo.java
/** * Permite enviar la nueva lista de registros * * @param campos/*from ww w .j a v a2s. c o m*/ * @param archivo */ public static void insetarCampos(ArrayList<String> campos, File archivo) { for (int i = 0; i < campos.size(); i++) { insertar(campos.get(i), archivo); } }
From source file:com.milaboratory.core.io.util.TestUtil.java
public static String[] getAllLines(File file) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); ArrayList<String> list = new ArrayList<>(); String line;// w ww . jav a 2 s. co m while ((line = reader.readLine()) != null) { list.add(line); } return list.toArray(new String[list.size()]); }