So I have a List collection that I fetch via a API call (which I don't have any control over).
The list is ordered.
public class Article
{
articleID,
string Url
}
So I have a Url value, using that I want to figure out the next and previous Url's if any.
What's the most elegant way of doing this?
I have a question that I dont really know where to start. So I thought i'd ask it here.
Basically, I have a drop down with names in it. I want these names to be in alphabetical order.
Populating the drop down happens as follows;
I query a database and pull down an Id and Name, make a object called "UserList", and set the name and id variables with what I get back.
I then add this object to an ArrayList. I do this over and over.
I then convert this collection to an array, and pass it to my JSP page using
session.setAttribute("userList", UserList);
I then populate the drop down as below.
<c:forEach items="${usersCompanysList}" var="c" >
There probably is a simple answer but how to I sort these names?
I am wonder why after creating a very simple DataTable and then setting it to null why Garbage Collection does not clear out all the memory used by that DataTable. Here is an example. The variable Before should be equal to Removed but it is not.
{
long Before = 0, After = 0, Removed = 0, Collected = 0;
Before = GC.GetTotalMemory(true);
DataTable dt = GetSomeDataTableFromSql();
After = GC.GetTotalMemory(true);
dt = null;
Removed = GC.GetTotalMemory(true);
GC.Collect();
Collected = GC.GetTotalMemory(true);
}
Gives the following results.
Before = 388116
After = 731248
Removed = 530176
Collected = 530176
Hello everyone.
We all know you can't do this:
for (Object i : l)
if (condition(i)) l.remove(i);
ConcurrentModificationException etc... this apparently works sometimes, but not always. Here's some specific code:
public static void main(String[] args)
{
Collection<Integer> l = new ArrayList<Integer>();
for (int i=0; i < 10; ++i) {
l.add(new Integer(4));
l.add(new Integer(5));
l.add(new Integer(6));
}
for (Integer i : l)
{
if (i.intValue() == 5)
l.remove(i);
}
System.out.println(l);
}
This, of course, results in:
Exception in thread "main" java.util.ConcurrentModificationException
...even though multiple threads aren't doing it... Anyway.
What's the best solution to this problem? "Best" here means most time and space efficient (I realize you can't always have both!) I'm also using an arbitrary Collection here, not necessarily an ArrayList, so you can't rely on get.
I've a collection type:
Collection<A> collecA
And I've a list in my object:
List<B> listB
Where B is extending A
class B extends A { ... }
But I can't do the following:
collecA = listB
I can't understand why since Collection is implemented by List.
This is something I encounter frequently, but I don't know the elegant way of doing. I have a collection of Foo objects. Foo has a method bar() that may return null or a Bar object. I want to scan the collection, calling each object's bar() method and stop on the first one returning an actual reference and return that reference from the scan.
Obviously:
foos.find(_.bar != null).bar
does the trick, but calls #bar twice.
I'm trying to store types in a collection, so that i can later instantiate objects of the types in the collection. But I'm not sure how to do this the best way.
What i have so far:
List<Type> list = new List<Type>();
list.Add(typeof(MyClass));
var obj = (MyClass)Activator.CreateInstance(list[0]);
I would like to have some constrains on the Type, or better yet, just a generic type in the collection instead of an instantiated Type object. Is this possible?
I'm binding a GridView to a collection of objects that look like this:
public class Transaction
{
public string PersonName { get; set; }
public DateTime TransactionDate { get; set; }
public MoneyCollection TransactedMoney { get; set;}
}
MoneyCollection simply inherits from ObservableCollection<T>, and is a collection of MyMoney type object.
In my GridView, I just want to bind a column to the MoneyCollection's ToString() method. However, binding it directly to the TransactedMoney property makes every entry display the text "(Collection)", and the ToString() method is never called.
I understand that it is binding to the collection's default view. So my question is - how can I make it bind to the collection in such a way that it calls the ToString() method on it?
This is my first WPF project, so I know this might be a bit noobish, but pointers would be very welcome.
Hello, i have some pb. I want to cast a List to Collection in java
Collection<T> collection = new Collection<T>(mylList);
but i have this error
Can not instantiate the type Collection
I have a private LinkedList in a Java class & will frequently need to retrieve the last element in the list. The lists need to scale, so I'm trying to decide whether I need to keep a reference to the last element when I make changes (to achieve O(1)) or if the LinkedList class does that already with the getLast() call.
What is the big-O cost of LinkedList.getLast() and is it documented? (i.e. can I rely on this answer or should I make no assumptions & cache it even if it's O(1)?)
I need to create a Set of objects. The concern is I do not want to base the hashing or the equality on the objects' hashCode and equals implementation. Instead, I want the hash code and equality to be based only on each object's reference identity (i.e.: the value of the reference pointer).
I'm not sure how to do this in Java.
The reasoning behind this is my objects do not reliably implement equals or hashCode, and in this case reference identity is good enough.
I have an Iterator that I use on a HashMap, and I save and load the iterator.
is there a way to get the previous key in the HashMap with Iterator? (java.util.Iterator)
Update
I save it as an attribute in a Red5 connection and then load it back to continue working where i stopped.
Another update
I'm iterating through the keyset of the HashMap
My question, is, whether the sequence of elements picked from a list will always be the same,
is this construction behaviour is deterministic for
java "List"s - descendants of java.util.List
2) question, if I use for(Object o: list) construction and inside the loop's body increment a variable,
will it be the index of list's elements? So, how it goes through list's elements, from 0 to size()-1 or chaotically?
List.get(i)
will always return this element?
3) question ( I suppose for the 2-nd question the answer will be negative, so:)
for (int i=0; i < list.size(); i++) {
}
is the best way if I need to save the index of an element and later get it back from a list by its id?
Hiya.
I have an Iterator that I use on a HashMap, and i save and load the iterator.
is there a way to get the previous key in the HashMap with Iterator? (java.util.Iterator)
Update
I save it as an attribute in a Red5 connection and then load it back to continue working where i stopped.
Another update
I'm iteratoring through the keyset of the HashMap
I want to convert the items to a String array or the type that I used to fill the ListBox.DataSource. The type has overridden ToString() but I can't seems to get it converted, not even to String[].
String[] a = (String[])ListBox1.Items;
Contacts[] b = (Contacts[])ListBox1.Items;
I have a requirement to implement some kind of dictionary object. Something like MyDict<K,V1, V2). For example if I have a Question as Key(k) then Correct answer is V1 . V2 is user selected answer. Is there a collection that would satisfy this requirement in C#. If I have to design my own type, what interfaces should I implement. ICollection and Ilist ?
Hello All,
I have a following ArrayList,
[Title,Data1,Data2,Data3]
[A,2,3,4]
[B,3,5,7]
And I would like to convert this one like this,
[Title,A,B]
[Data1,2,3]
[Data2,3,5]
[Data3,4,7]
I'm bit confused with the approach. Any hint would be much appreciated.
Thanks.
If I run this operation on List<Integer> for example, it works as expected (removes first 5 elements), but when I run it on a list of my objects, nothing happens (list stays the same).
list.subList(0, 5).clear();
My class is a pojo that doesn't implement equals or hashCode, if that matters.
My dell vostro laptop keeps on restarting when I'm busy using it without commanding it to do so.I'm using windows 7 for O.S.What might be the problem?How can I solve it?Please someone help!
And here it is, the long awaited "ABC" of front end web development, in which the items I never knew existed until I was looking to fill the gaps link off to the sites where more info can be found on them.
A is for Android and AngularJS
B is for Backbone.js and Bower
C is for CSS and Cordova
D is for Docker
E is for Ember.js and Ext JS
F is for Frisby.js
G is for Grunt
H is for HTML
I is for Ionic and iPhone
J is for JavaScript, Jasmine, and JSON
K is for Knockout.js and Karma
L is for LESS
M is for Mocha
N is for NetBeans and Node.js
O is for "Oh no, my JS app is unmaintainable!"
P is for PHP, Protractor, and PhoneGap
Q is for Queen.js
R is for Request.js
S is for SASS, Selenium, and Sublime
T is for TestFairy
U is for Umbrella
V is for Vaadin
W is for WebStorm
X is for XML
Y is for Yeoman
Z is for Zebra
Photobooth.js : le framework JavaScript permet d'ajouter un système de webcam
à un site Web en utilisant HTML5
Le HTML5, le futur standard du Web vient de révéler une fois de plus l'une de ses nombreuses facettes.
Un développeur indépendant a exploité les nouveautés du langage pour mettre au point Photobooth.js, une bibliothèque open source en JavaScript qui permet d'intégrer dans un site Web assez aisément un système de prise de photo par webcam.
Photobooth s'appuie sur la méthode getUserMedia du framework audio et vidéo open source WebRTC, qui est actuellement en cours de standardisation par le W3C comme une partie du HTML5.
Photobooth.js permet de prendre dire...