duplicates

Java Scanner class reading strings

ⅰ亾dé卋堺 提交于 2019-11-27 20:28:24
I got the following code: int nnames; String names[]; System.out.print("How many names are you going to save: "); Scanner in = new Scanner(System.in); nnames = in.nextInt(); names = new String[nnames]; for (int i = 0; i < names.length; i++){ System.out.print("Type a name: "); names[i] = in.nextLine(); } And the output for that code is the following: How many names are you going to save:3 Type a name: Type a name: John Doe Type a name: John Lennon Notice how it skipped the first name entry?? It skipped it and went straight for the second name entry. I have tried looking what causes this but I

How to check if exists any duplicate in Java 8 Streams?

荒凉一梦 提交于 2019-11-27 20:23:25
In java 8, what's the best way to check if a List contains any duplicate? My idea was something like: list.size() != list.stream().distinct().count() Is it the best way? Your code would need to iterate over all elements. If you want to make sure that there are no duplicates simple method like public static <T> boolean areAllUnique(List<T> list){ Set<T> set = new HashSet<>(); for (T t: list){ if (!set.add(t)) return false; } return true; } would be more efficient since it can give you false immediately when first non-unique element would be found. This method could also be rewritten as

Cloning a record in rails, is it possible to clone associations and deep copy?

醉酒当歌 提交于 2019-11-27 20:03:47
I'm .clone -ing a record in rails... new_blerg = Blerg.find(1).clone This record has loads and loads of associations, and those associations even have associations. Is there a way to deep-copy a record and clone it so it is cloned with all of those associations too? Vaughn Draughon You may get some good use out of the Amoeba gem for ActiveRecord 3.2. It supports easy and automatic recursive duplication of has_one , has_many and has_and_belongs_to_many associations, field preprocessing and a highly flexible and powerful configuration DSL that can be applied both to the model and on the fly. be

Entity Framework. View return duplicate records

核能气质少年 提交于 2019-11-27 20:01:48
问题 I use Entity Framework that contains view. And I have query: var data = this.context.vwRevenues .Where(x => x.revenue >= 0); .OrderByDescending(x => x.year) .ThenByDescending(x => x.month) .Take(10) .ToList(); This query returns set of entities, but 1st entity equals 5th. data[0] == data[4] // true I take sql script for this query from sql tracer and run it into SQL Management Studio, it returns different records. 回答1: As per @Giovane Answer's We had the same problem in our system with Entity

Determining duplicate values in an array

社会主义新天地 提交于 2019-11-27 19:56:11
问题 Suppose I have an array a = np.array([1, 2, 1, 3, 3, 3, 0]) How can I (efficiently, Pythonically) find which elements of a are duplicates (i.e., non-unique values)? In this case the result would be array([1, 3, 3]) or possibly array([1, 3]) if efficient. I've come up with a few methods that appear to work: Masking m = np.zeros_like(a, dtype=bool) m[np.unique(a, return_index=True)[1]] = True a[~m] Set operations a[~np.in1d(np.arange(len(a)), np.unique(a, return_index=True)[1], assume_unique

python count duplicate in list

丶灬走出姿态 提交于 2019-11-27 19:36:52
问题 i have this list: ['Boston Americans', 'New York Giants', 'Chicago White Sox', 'Chicago Cubs', 'Chicago Cubs', 'Pittsburgh Pirates', 'Philadelphia Athletics', 'Philadelphia Athletics', 'Boston Red Sox', 'Philadelphia Athletics', 'Boston Braves', 'Boston Red Sox', 'Boston Red Sox', 'Chicago White Sox', 'Boston Red Sox', 'Cincinnati Reds', 'Cleveland Indians', 'New York Giants', 'New York Giants', 'New York Yankees', 'Washington Senators', 'Pittsburgh Pirates', 'St. Louis Cardinals', 'New York

How can i duplicate a div onclick with javascript?

落爺英雄遲暮 提交于 2019-11-27 19:24:39
I want a div to be duplicated when a button is clicked. I though something like this; but it's not working. Can anyone help me? HTML <div id="duplicater"> duplicate EVERYTHING INSIDE THIS DIV </div> JAVASCRIPT function duplicate() { var div = duplicate("div"); div.id = "duplicater"; div.appendChild(duplicate("duplicater")); } Felix Kling You are creating an infinite recursion! function duplicate() { var div = duplicate("div"); The function is calling itself over and over again. Use cloneNode() : HTML: <div id="duplicater0"> duplicate EVERYTHING INSIDE THIS DIV </div> JavaScript: var i = 0;

How can I use ON DUPLICATE KEY UPDATE in PDO with mysql?

半世苍凉 提交于 2019-11-27 18:57:14
问题 DETAILS I am doing a single insert for the expiry of a new or renewed licence. The time period for the expiry is 2 years from the insertion date. If a duplicate is detected, the entry will be updated such that the expiry equals the remaining expiry plus 2 years. Regarding duplicates, in the example below there should only be one row containing user_id =55 and licence=commercial. TABLE: licence_expiry -------------------------------------------------------- | user_id | licence | expiry | -----

Deduplicate Git forks on a server

僤鯓⒐⒋嵵緔 提交于 2019-11-27 18:30:45
问题 Is there a way to hard-link all the duplicate objects in a folder containing multiple Git repositories? Explanation: I am hosting a Git server on my company server (Linux machine). The idea is to have a main canonical repository, to which every user doesn't have push access to, but every user forks the canonical repository (clones the canonical to the user's home directory, thereby creating hard-links actually). /canonical/Repo /Dev1/Repo (objects Hard-linked to /canonical/Repo to when

How to select records without duplicate on just one field in SQL?

丶灬走出姿态 提交于 2019-11-27 18:18:16
I have a table with 3 columns like this: +------------+---------------+-------+ | Country_id | country_title | State | +------------+---------------+-------+ There are many records in this table. Some of them have state and some other don't. Now, imagine these records: 1 | Canada | Alberta 2 | Canada | British Columbia 3 | Canada | Manitoba 4 | China | I need to have country names without any duplicate. Actually I need their id and title , What is the best SQL command to make this? I used DISTINCT in the form below but I could not achieve an appropriate result. SELECT DISTINCT title,id FROM