This problem occurs over and over. I have some complicated object, such as a Cat, which has many properties, such as age, favorite cat food, and so forth.
A ...
Am I correct in assuming that if you have an object that is contained inside a Java Set<> (or as a key in a Map<> for that matter), any fields that ...
I'm a .NET guy originally, working in Java recently, and finding I'm really missing LINQ to Objects, specifically for performing filtering against collections.
A few people here on Stack Overflow have ...
I want to create a collection of objects that implement a given interface (in C# it would be something like Collection<IMyInterface>). I don't care about sorting or indexed access but would ...
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 ...
I am making a java program that has a collection of flash-card like objects. I store the objects in a jtree composed of defaultmutabletreenodes. Each node has a user object attached ...
Say you are adding x number of objects to a collection, and after or before adding them to a collection you are modifying the objects attributes. When would you add the ...
I have a List of MyObjects ... MyObject{ int id,String name}. Now I want to split the the list into sublists that have identical "id" values, can any one suggest an ...
I understand that time taken by YGC is proportional to number of live objects in Eden. I also understand that how the live objects are figured out in Major collections (All ...
Is it possible to validate a collection of objects in JSR 303 - Jave Bean Validation where the collection itself does not have any annotations but the elements contained within do?
For ...
I have an Enumeration object and I want to create a Collection object containing the items of the enumeration.
Is there any Java function to do this without manually iterating over the ...
I have an abstract class that implements an interface. I then have several classes that extends that abstract class that are in turn composed of a hierarchy of some objects ...
I'm wondering how to go about checking that a method returns a container encapsulating some collection which is the aggregate of multiple other containers returned by mock objects. That is, it ...
That's the brute force approach, but it assumes all the objects implement the Comparable interface, which is probably valid otherwise they can't be sorted The other approach is to consider one of the sorted collections such as the TreeMap or TreeSet which sort the data as it is entered and therefore it is always returned in it's natural sorted order. Whether ...
Hmmm, you always learn from questions. I'd never looked at AbstractList before. List and Collection are interfaces. If you write a class that implements Collection then you (and others) can use your class any place they would use any other Collection implementation. When you add "implements Collection" to your class, you promise to implement all the methods defined by Collection. There ...
The javadoc says this about System.gc(): gc public static void gc() Runs the garbage collector. Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to ...
In my application, I'm creating an object that may be referenced in multiple locations (added into multiple Collections). Change it once and it is changed for all the different references (correct functionality - everyone sees the change). What I need is the ability to delete the object (remove all the references in the assorted collections, etc..). Is there some design pattern ...
hey, guys: I need urgent help for the following problem domain: I have a collection containing, for example, 10 People objects.There are at least some People objects are identical. I want to iterate this collection and identify how many identical People objects within this collection and also list their first name , last name and sum of age as a report. ...
I will hazard a rewrite of the post, as I understand it. "In Java, objects can be stored in Collections. How can we store objects without using Collections and DataStructures (i.e. Arrays)". Assuming "store" means "store for retrieval later", seems the question is about storing objects for retrieval but without using Collections, or anything that is a data structure. Which is ...
If I have one object, then I add that object to a collection... how many instances of that object do I have? example: MyClass c = new MyClass(); c.setString("Before adding to collection"); List myList = new ArrayList(); myList.add(c); c.setString("Added to the collection"); MyClass b = (MyClass) myList.get(0); System.out.println(b.getString()); output is "Added to the collection", but if I set c = null ...
Hi all I have question about collections, and getting a particular object or objects out of a collection if I define a class of type Column, which had a Boolean Primary Key indicator. I have a table user ( usercode, name, password, contactdetails ) of which usercode and name are primary keys. Now if I populate a collection of Columns with ...
I have a program as follows: import java.util.*; class Address{ private String name; private String street; private String city; private String state; private String zipcode; Address(String n, String s, String c, String st, String z){ name = n; street = s; city = c; state = st; zipcode = z; } } class MailList{ public static void main(String args[]){ LinkedList ml ...
Hi, I have a small object graph that looks like this: class Root { ArrayList foos; // containing Foo objects ArrayList bars; // containing Bar objects } class Bar { Foo foo; public Bar(Foo foo) { this.foo = foo; } } When I run my application, it will start populating the "foos" collection. Later instances of "Bar" are created and added ...
You can always cast an object to another object that is (directly or indirectly) above it in the object hierarchy. Since Object is the root of the hierarchy, every object can be cast to it. Of course, you lose the ability to use all the features that distinguish it from Object. As to your second question, that depends on what you're ...
hey i m not able to do an application, that maybe simple for many out there, please help me? i have to generate a table using two collections -> Parent and Child it should build a table like this Output - In a table format: =========================== 670Dana Cirovic AcceptedMark Jones CompletedSarah Smith 563Eric Suto 670Dana Cirovic RejectedJudy Garland i m a ...
My apologies... I clearly understood the naming policy for the website. Maybe I am not able to understand whats wrong with my display name or I am not making the changes in the right place. What I see as my display name is "Sabrina Kr" which is exactly who I am. I am sure I dont understand what could be wrong ...
I'm working on a university project using BlueJ. It involves creating a GUI that displays nine buttons that each hold a value from 1 to 9. I need to know how to iterate through the collection of buttons and return their combined value (45 in this case). My array is called gameTile and its initialized as: gameTile = new Tile[9]; for(int ...
IMO List (ArrayList, LinkedList) would be a better option *if* the only source of records is the database. When retrieving the records use the SQL order by clause and there will be no need to sort. However if more records are added to the collection after filling it with the database records, I would say following Rob's suggestion.
You are trying to add a Node to a collection that holds "something that is a subclass of Node". What if your fringe happens to be an ArrayList>? Clearly, you are not allowed to add some Node when it expects a SubNode. One solution is to remove the upper bound on your fringe: simply make it a Collection>.
I'm trying to sort objects based on the name. I don't know where Im going wrong. Code seems understandable and legal to me but keep on getting the error "The constructor SortMe.Man() is undefined" on top of New Man(). import java.util.*; public class SortMe{ public static void main(String args[]){ ArrayList list = new ArrayList(); Man m1 = new Man(); m1.Name = ...
I have a TreeSet of values. One value contains an apostrophe. When the contents of the TreeSet are listed, instead of an apostrophe, it displays another character. I tried changing the TreeSet to an ArrayList, with the same result. How do I get around this? Set names = new TreeSet(); //List names = new ArrayList(); names.add("IVS,"); // value between 'V' and ...
Hi, Im pretty new to java although not new to programming in general. I wish to create an entity (for example, call it "BookClub"). That entity can have an unknown number of child objects (for example call them "Members"). I want to have a collection that I can call methods on (for example "BookClub.sendMessage()"). In this way, I can write some ...
I want to add the objects marked by some sequence no.(fetching it from database) to any Collection like ArrayList, LinkedList. But when adding this,it throws exception. For example : List aa = new ArrayList(1000); aa.add(4, "e"); aa.add(5, "f"); aa.add(1, "b"); aa.add(0, "a"); aa.add(3, "d"); aa.add(2, "c"); System.out.println("LinkedList : "+aa); (first index may not come first)Please suggest how to solve this problem. ...
Ah. So if I were passing just a "Consumeable" when the constructor specified an "Action", that would be acceptable, but because it's a Vector and not just a Consumeable, they're unrelated? Interesting. Thanks for the quote. Any recommendation on how to get around this? I tried creating a separate constructor for Vector but Eclipse then proceeded to give me an error ...
Hello I have a requirement to call a method that executes a large amount of complex code a number of times. The code creates new class objects and does database look ups and updates. I intended to create a new instance of the class object for each time the code needs to be run. Is this the best approach or should ...
Hi, I have some questions given to me from a seminar, and this is one question that I'm stuck on. Given this method signature /** * Add a new member to the club's collection of members. * @param member The member object to be added. public void join(Membership member) Complete the join method. I am not sure how to complete the ...
Yes I'm not very experienced (just over a year of java) and i know this is fairly difficult and big project and i expect it to take quite a long time but i hope with your guys help and any tutorials i find around i can do this. Plus good old trial and error
Well I suppose I could change to a List. It is just that everyone here at my corp. use a standard to hold multiple custom Class Objects inside a Collection type. I am not sure what the impact could be If I start to hold custom class objects inside a List. What do you think Dr ? and.... Thank you kevjava, ...
Hi I need to read some data from the Sybase database and make some statistical computations( average, standard Deviation, min/max) for monthly period. The data looks like the following: Name Score Date John 100 06/20/2009 Mike 200 05/23/2009 . . . Performance is very important, what is the best way to store that information in a java collection ( I think ...
I first sorted the "activities" by color. So far so good. Thereafter, I am iterating through this sorted list. If activity.getColor().trim() is So in fact you are not dealing with an arbitrary Collection (as you stated in the first place), you are dealing with a List. You should know that there is a way to do this just with an iterator ...
I am trying to figure out how I might compare a collection of Date objects to each other, to find the oldest date, remove it from the list, and then repeat the process. I can see that Date.compareTo(Date) lets me compare two objects, but i am not sure how i could apply this to a collection of Dates Any thoughts? Regards ...
Basically if I remove from the list so that it can hold any type of data, I can successfully add an int: 123 and a string "testing" to the list, then when the iterator runs the two items are retreived, but when I try to add an engagement object and run the iterator all I get as output is: null ...
Hi, How do i find the closest values in a vector or hashtable, to a given number. example: let's say a vector or hashtable contains these numbers: 1562221 1981112 2654489 3023121 3506652 4022258 if i pass the number "1562230" to a method it should return the number "1562221" and "1981112" (which are the closest numbers). Note: Actually each number in vector ...
I am using JSF framework.In that if we set any valueto a input field then it must set to the property in DTO class.Similarly, if we want to get the value,we use get method available in DTO class. the data for ArrayList is taken from te database table.I deleted some code from the method bcoz it is too lengthy.