Most voted "collection" questions
A Collection object represents a generic grouping of simple objects.
Learn more…81 questions
Sort by count of
-
17
votes2
answers964
viewsWhy doesn’t polymorphism work with Generics?
When trying to compile the following code I got an error. import java.util.*; class Animal { } class Cachorro extends Animal { } public class TestePoli { public static void main(String[] args) {…
-
13
votes3
answers4045
viewsHow to add <li> dynamically in <ul> with jQuery?
I’m bringing back notifications and need to dynamically add the path to them, how do I add a <li> to each element of the response? Javascript $(document).ready(function () { $.ajax({ url:…
-
13
votes1
answer1046
viewsWhat are the differences between Treeset, Hashset and Linkedhashset?
The idea of Set is to not allow repeated elements, in java there are three implementations TreeSet, HashSet and LinkedHashSet found some differences in that reply, would like to know in detail if…
-
9
votes1
answer1858
viewsWhat are the differences between Hashmap and Hashtable?
What are the differences between HashMap and Hashtable in Java? Which is more efficient?
-
8
votes2
answers385
viewsIn which scenario is it recommended to use Keyedcollection instead of a Dictionary?
I didn’t know about the existence of KeyedCollection until you see this reply gypsy. I wondered how and when to use a KeyedCollection, since there is the Dictionary which apparently has the same…
-
7
votes1
answer282
viewsHashmap sorting by value and assigning to a dto using java 8
I currently have the following scenario functional: A list of the Studios class with id and name: List<Studios> studios; I count the names repeated on List thus: Map<String, Integer>…
-
6
votes4
answers640
viewsJava abstract class exercise doubt
I would like to ask for your help again in this exercise. This time using the abstract class. Create an abstract class FuncionarioAbstract with the attribute String name and abstract method: public…
-
6
votes3
answers1428
viewsHow to define the comparison of equality between two objects present in an Arraylist?
How can I define the equality comparison behavior between two objects whose class is defined by me that are stored in an Arraylist object? Java nomecor. public class NomeCor { private String nome;…
-
5
votes1
answer727
viewsHow to create a value pair within a Java Map
It is possible to create a Map in Java using the concept of pair that exists in C++? I have tried to use it in the form below, however, I cannot assign values to my map. Map<String,…
-
5
votes1
answer4346
viewsHow to sort alphabetically and numerically the same list?
In my college work I must make a list of the kind of class I created and I must sort it in two different ways, one by alphabetical order and the other by average score. Also other information is…
-
5
votes1
answer411
viewsWhat is the Scala Collection equivalent to Concurrenthashmap?
Hello, how can I implement a Concurrenthashmap in Scala?
-
5
votes1
answer87
viewsJava int[] arraylist
I’m creating a list from a array using the method Arrays.asList. Now I want to remove the first element, but Java accuses: Exception in thread "main" java.lang.Unsupportedoperationexception…
-
4
votes3
answers1646
viewsJava Maps: take key from value
Hello, I have a string map for string: Map<String,String> myMap = new Map<String,String>(); with a series of values myMap.put("1","valor1"); myMap.put("2","valor2");…
-
4
votes2
answers851
viewsSort items from a Collection from a preset value
I have a Collection of the Eloquent and I would like to order it through two fields at the same time being one of them a predefined value. Ex.: this one Collection has several objects of the type…
-
4
votes1
answer1091
viewsBest way to go through a Hashset
I’m used to programming in PHP and now I’m studying Java, and the Collections API is something new and very interesting for me. I searched the internet and easily found several ways to go through a…
-
4
votes5
answers212
viewsGet array object by description in index
It is possible to use the property of an object as an index of a array, as described in the example below? using System; public class Program { public static void Main() { var myObjectArray = new…
-
3
votes2
answers7797
viewsRemove duplicate objects from List<Minhaclasse>
Guys is the following, I have a model class with attributes that store data returned from the database. For example: public class RelacaoTransformacao { /** ID do registro no banco de dados. */…
-
3
votes2
answers5037
viewsSort a list of objects by more than one attribute
How to sort a list of objects by more than one attribute? First is made the ordering of the score, then as tiebreaker criteria we have the winning number and then the goal balance. Something like…
-
3
votes3
answers2350
viewsAdd multiple items to a list
Is there any way to add several Intin a list<int>all at once? Type List<Int32> ContasNegativas = new List<Int32>(); ContasNegativas.AddRange(30301, 30302, 30303, 30304, 30305,…
-
3
votes2
answers72
viewsI don’t understand what’s going on with this controller class, explain it to me?
I really don’t get it, if someone could draw it for me,. class DisciplinaController extends GenericController<Disciplina>{ DisciplinaController() { super(Disciplina.class) } }…
-
3
votes1
answer90
viewsSort products interchange according to flag
I have a model called Product which has, in addition to product data, a flag featured that says whether the products are featured or not. When mounting the view the products should be displayed…
-
3
votes1
answer54
viewsFor an unordered set of listeners what is the best java.util.Set implementation to use?
I’m developing a Handle to a data stream, where periodically events will be launched that are to be captured by a small set of Listeners from 1 to 5 listeners. This set of listeners do not need to…
-
3
votes1
answer403
viewsHow to use Java 8 Stream in an Object[] list
Imagine the following scenario: A list of Object[]. Something like that: List<Object[]> lista = new ArrayList<>(); Object[] dados = new Object[3]; dados[0] = 1; dados[1] = 20; dados[1] =…
-
3
votes1
answer936
viewsWhen to use Collections.emptyList()?
I thought I’d use List<Object> lista = Collections.emptyList(); to initialize a list. But when I try to do lista.add(element) I get a UnsupportedOperationException. After researching a little,…
-
3
votes1
answer184
viewsWhat is the difference between arrays vs. Collections in C#?
Concerning arrays and Collections in C#, vary from application to application or there is unanimity between them?
-
2
votes1
answer315
viewsCollection Map<k,v> Methods
Doubts about the methods replace : compute : computeIfAbsent : computeIfPresent :forEach(briefly all who make use of the function or biFuntion within the input parameter) The replace is it really…
-
2
votes1
answer365
viewsCollection Namedquery as Parameter
I am using the Namedquery of JPA, to create a DTO. And in my Query I have as condition one IN and as a parameter of IN has values with white spaces in the middle. (Ex: 9292 929). and these values…
-
2
votes3
answers1152
viewsHow to make an object array have only unique values?
If I have a collection with the same object in one array, how could I make this collection with only objects of unique instances? Example: $a = new stdClass; $a->id = 1; $b = $a; // mesmo objeto…
-
2
votes1
answer44
viewsSave Ienumerable<T> inside a parent entity with LINQ
I have the following classes: public class Foto { [Key] public int Id { get; set; } [StringLength(500)] [Required(ErrorMessage = "Obrigatório")] public string Nome { get; set; } public int Item_Id {…
-
2
votes1
answer124
viewsDictionary<string, string> or Namevaluecollection?
What’s the difference in using Dictionary<string, string> and NameValueCollection? I researched, but only found in English in the same Sopt, I used the translator, but the translation became…
-
2
votes1
answer440
viewsRelationship between Mongodb collections
I wonder if it is good practice to create a relationship between two collections (Collections) in Mongodb. Suppose I have a collection for users, with a scheme like this: { "_id": ObjectId(...),…
-
2
votes1
answer47
viewsIf B is a subtype of A, why is a collection of B not a subtype of a collection of A?
Dice: public interface A { ... } public interface B extends A { ... } private Set<B> bs = new HashSet<>(); RecebeA qualquerCoisa = new RecebeA(bs); Why does the last line compile if the…
-
2
votes0
answers66
viewsIntersection of two collections of nodes with jQuery
I was trying to create a pseudo-search function by filtering the results of Hugo’s taxonomy that nay recursion for all nodes or, rather, related terms with each other, more or less like this: |-\…
-
2
votes2
answers458
viewsSort a java List containing null values
Good morning! In my List, when I do the ordering I would like the null values to be last. I’ll show you an example to make it clear: Code output (in this case the word would be the letter after the…
java list arraylist comparison collectionasked 6 years, 10 months ago Carlos Rafael de Oliveira Carn 50 -
2
votes1
answer232
viewsError: Collections.defaultdict' Object has in Python iteritems attribute
When executing the code below the compiler returns the following message: collections.defaultdict' object has no attribute 'iteritems' I’m using version 3.6.5 of Python. Follows the code: import…
-
1
votes1
answer67
viewsHow to create a Weakhashset /Weakset in Java
The java.lang.ref package offers classes that model reference types in Java, such as Reference, Softreferece, Weakreference and Phantomreference. Still not familiar with these references in Java?…
-
1
votes1
answer101
viewsHow to automatically add lines (label) to an Uicollection in Swift?
In my application I managed to use Uicollection to show a "table" with horizontal scrolling containing the purchase information of the customer with header, but now I have another question, I need…
-
1
votes1
answer393
viewsHow can I move an element from an Arraylist to the last element ?
I would like to know if there is any method to perform the operation, other than to concatenate manually. Example of what you wanted: [1,2,3,4] -> [1,3,4,2]
-
1
votes1
answer854
viewsList, virtual and Entity Framework
In all the examples I have found about Entity framework, always use ICollection for collections of objects. public partial class Standard { public Standard() { this.Students = new…
-
1
votes2
answers102
viewsHow to assign the callback variable "cursor.toArray(err, doc)" to an external variable?
var result = []; var user = db.collection('user'); var cursor = user.find(); cursor.toArray(function (err, doc) { result = doc; }); console.log(result); // console ->…
-
1
votes1
answer374
viewsHow to order a table using Collections?
I’m developing an application similar to the Olympic medal board. I’ve done the classes and the table with the countries and their medals. Now I’m hooked on the part I need to organize the table by…
-
1
votes1
answer35
viewsConversion c# wpf Icollection and Observablecollection
I have a list Icollection Generica and need to convert to Observablecollection, so I do not know which class is to convert to ObservableCollection<MyClass>. I’ve been searching for that answer…
-
1
votes1
answer100
viewsIcollection in Put Webapi method
I have the Put method in a Webapi Rest service // PUT: api/pessoas/5 [ResponseType(typeof(void))] public IHttpActionResult Putpessoa(int id, pessoa pessoa) { if (!ModelState.IsValid) { return…
-
1
votes1
answer600
viewsUse the Laravel diff in two Collections
I am trying to fetch items that are not in a particular product. I therefore have a model Produto, each product has several items, and another model Item. I’m trying to use Collections of Laravel,…
-
1
votes1
answer600
viewsUse the Laravel diff in two Collections
I am trying to fetch items that are not in a particular product. I therefore have a model Produto, each product has several items, and another model Item. I’m trying to use Collections of Laravel,…
-
1
votes0
answers308
viewsCRUD - LARAVEL 5.6
I am developing a CRUD and in my controller I have create function: public function create() { $neighborhood = new Neighborhood(); $city = new City(); return view( view: 'admin.cities.create',…
-
1
votes1
answer124
viewsreverseOrder() In java not reversing
I have a method in java to sort a vector in a decreasing method, but when I run the test it returns me the unpaired vector. Follows the Method: public void sort() { int vet[] = this.vetor;…
-
1
votes1
answer85
viewsAbstract class to access elements from an object collection
I’m doing my first project on C#, I’m creating data from a multi-object JSON file that contains basic information from a file (Filename, Datacreation, Size). Filing cabinet jsonArquivos.json: [ {…
-
1
votes1
answer39
viewsProblem with coding in phpmyadmin on remote server
The problem is this. I am developing a site locally in PHP with access to database and I am facing coding problems, but this problem only happens in hosting, works normally on the local server.…
-
1
votes1
answer28
viewsWhy do I still have access to the current state of the object in this case? [EXAMPLE C#]
A very basic doubt, but it’s bugging my head. I have the following code snippet: A class that receives a list as a parameter in the constructor: public class MinhaClasse { IList<int> Items;…