If I have an ArrayList of Objects, and I want to sort them by one of the fields (string) in the Object, how would I do that?
|
|
# ¿ Mar 5, 2008 04:29 |
|
|
# ¿ May 4, 2024 20:37 |
MEAT TREAT posted:If you can change your objects you can have them implement the Comparator interface. Now you can use the sort the function in java.util.Collections class. Ok cool, that led me to this code:
fletcher fucked around with this message at 04:49 on Mar 5, 2008 |
|
# ¿ Mar 5, 2008 04:46 |
Hah well I feel like an rear end. Thank you! Works great now.
|
|
# ¿ Mar 5, 2008 04:56 |
triplekungfu posted:What type is name in the Product class? If it's a String already, you don't need those casts to String. It's only a minor issue, but every time I see stuff like that at work I die a little. Thanks for the tip. Normally I'd try it both ways, but not when I needed to get that code checked in ASAP. I was just copying the example code from the link up above. fletcher fucked around with this message at 15:21 on Mar 5, 2008 |
|
# ¿ Mar 5, 2008 15:19 |
Is there a way to do this without int count?code:
|
|
# ¿ Apr 8, 2008 00:50 |
edit: nevermind
|
|
# ¿ Apr 8, 2008 04:37 |
Thank you to all the replies about my previous question. I've got another one for you guys. I want to find unique values from a collection SomeCollection. Right now I'm just iterating through the collection and throwing every value into a HashMap<String, String> SomeUniqueCollection, where the key and value are both the key from SomeCollection. Should I be using a different type of collection for SomeUniqueCollection since I don't really need a K,V but just a K? Or is there a better way to approach this?
|
|
# ¿ Apr 9, 2008 22:15 |
1337JiveTurkey posted:HashSet does exactly what you're looking for. Right on, thanks!
|
|
# ¿ Apr 9, 2008 22:26 |
I'm looking to implement some charts on a Java web application. Right now I'm reading about JFreeChart. What are some others worth looking into? I'd prefer to go down either the static images route or possibly flash based for some user interaction, no applet type stuff.
fletcher fucked around with this message at 23:58 on Apr 25, 2008 |
|
# ¿ Apr 25, 2008 23:44 |
I'm trying to initiate a file download after a POST to a servlet, but it doesn't seem to work. What am I doing wrong? Almost the exact same code works for initiating a download from a GET request, just not for a POST. The only difference I see in firebug is Transfer-Encoding chunked. Do I need to set the content length? response is my HttpServletResponse object. code:
fletcher fucked around with this message at 01:57 on Jun 3, 2008 |
|
# ¿ Jun 3, 2008 01:37 |
Is there a way to define an operator in java? It's not really necessary for what I'm doing, I was just curious... Instead of: ArrayList<Double> pointsList = divide(aggregatedPoints, dataSetSum); Doing something like: ArrayList<Double> pointsList = aggregatedPoints/dataSetSum;
|
|
# ¿ Jun 19, 2008 23:16 |
BELL END posted:You'd probably have to cast one or both of the variables as a double for it to return a double, this should work with Java5 or later. I want it to return an ArrayList of Doubles, aggregatedPoints and dataSetSum are both ArrayList<Double>'s
|
|
# ¿ Jun 19, 2008 23:40 |
If I'm writing a function that looks like:code:
|
|
# ¿ Jun 25, 2008 22:19 |
Entheogen posted:make your own class that encapsulates results of the query and return ArrayList< query_encapsulation_class > Could you elaborate a little more? I'm a bit confused on your explanation. Do you mean doing something like: SyncInfo syncInfo, instead of having it be a HashMap<String, HashMap<String, String>> and put some logical methods for accessing the content of it? What about with the query results? fletcher fucked around with this message at 01:29 on Jun 26, 2008 |
|
# ¿ Jun 26, 2008 01:04 |
What's a good way to store a table of information? I want to use the same function and be able to output the results as an HTML table or as an excel spreadsheet using the POI HSSF stuff. There's a mix between strings, ints, etc that are going to go in the table.
|
|
# ¿ Jul 8, 2008 18:22 |
epswing posted:You might want to consider something out of the Swing library, namely the model that JTables use, TableModel. You can write your own implementation, or extend the existing DefaultTableModel to suit your needs. Sweet, thank you! Another question - I want to attempt to parse a date multiple times. If the first one fails I want to try a different format. The parse method throws a ParseException. What's the proper way to do what I want? It seems like it could be done with another try/catch inside the first catch, but that seems like the wrong way to do it.
|
|
# ¿ Jul 9, 2008 19:26 |
How do I make a copy of a LinkedHashMap? I want to modify products, but keep a copy of what the LinkedHashMap looked like before I modified the products. I thought declaring a new instance of a LHM and passing in the old one would work, but when I modify products, originalProducts is also modified. The clone() method for a LinkedHashMap doesn't seem at all useful, since it doesn't copy keys/values (what is it for?). code:
|
|
# ¿ Jul 16, 2008 01:11 |
What's an easy way to encode html entities with java?
|
|
# ¿ Jan 12, 2009 19:26 |
I have a string that contains some HTML that has <input> and <img> tags that aren't properly closed with a /> I'm thinking I can use the string.replaceAll(regex, replacement). I found a pattern that I want on regexlib. It seems to find them just fine, but I'm not sure what to put for the replacement string that will preserve what the rest of the attributes. somehtml = somehtml.replaceAll("<input([^>]*[^/])>", "<input />");
|
|
# ¿ Mar 6, 2009 19:17 |
Is there a good way to figure out what is wrong with the html I am trying to render as a PDF with Flying Saucer and ITextRenderer? I have to deal with these issues every now and then and it's always a pain trying to figure out what it's throwing up on when I get a stack trace like:code:
|
|
# ¿ Jul 31, 2009 22:33 |
I'm having an issue using the POI HSSF library to write to an Excel file. There are 10,000+ rows that I am trying to output, each row is identified with a username. It appears one of the usernames is not playing nice with the HSSF stuff, and I get a "This spreadsheet has unreadable content..." message. I've been trying to narrow down which username is causing problems and I'm not getting anywhere. What is strange is I found that replacing every character:code:
code:
Any suggestions?
|
|
# ¿ Sep 22, 2009 00:34 |
I've never done anything concurrently with threads and such in java. What's a good small project I can do to learn about them?
|
|
# ¿ Oct 17, 2009 01:56 |
What's a good way of figuring out the difference between two calendar objects and offsetting another calendar object by that amount? Right now I'm using Calendar.getTimeInMillis(), which returns a long, and then just casting it to an int and using Calendar.add(). There's got to be a better way than that. Maybe using a loop and increment it one day at a time and just count the number of iterations to get to the other calendar?
|
|
# ¿ Oct 24, 2009 01:51 |
I've got a string with an HTML snippet in it. I need a List of innerHTML for all the table cell elements. A regexp seems like the right tool, I'm just horrible at it. Can anybody help me out?
|
|
# ¿ Nov 5, 2009 18:39 |
Save the whales posted:Like this? Doesn't seem to work when the cell has an attribute: <td onclick="what()"></td>
|
|
# ¿ Nov 6, 2009 07:52 |
Thanks to both of you guys for the help, but I think I'm gonna have to go with epswing's solution for this one! Thank you!
|
|
# ¿ Nov 6, 2009 19:21 |
What is the best way to copy part of a byte array into another byte array? Do I have to loop through it and copy it 1 by 1?
|
|
# ¿ Dec 4, 2009 21:29 |
Mustach posted:java.util.Arrays.copyOf() Sweet! Worked great. Thank you!
|
|
# ¿ Dec 4, 2009 23:49 |
wwqd1123 posted:What I don't understand is why don't you have to go paint(Graphics g = new Graphics()) { because earlier on they mentioned that any object has to be created with the new command. I noticed that any time they create a new object from a class they always use the new command but not here? You could, but it would look more like: code:
code:
|
|
# ¿ Dec 24, 2009 10:56 |
I'm trying to find a good tutorial on using the org.w3c.dom stuff to output HTML. Is this not the correct tool for what I want to do? Or is there a template engine I should look at? edit: I found StringTemplate, looks like it should do just fine. fletcher fucked around with this message at 23:57 on Feb 1, 2010 |
|
# ¿ Feb 1, 2010 23:46 |
Looking for a way to generate some charts in Java and output to an image. JFreeChart looks pretty sweet, anything else I should check out before diving in?
|
|
# ¿ Feb 12, 2010 02:42 |
Parantumaton posted:Is pure image a necessity or are you doing a Web UI? Just need a static image for this one. Already using Open Flash Chart for the web stuff. necrobobsledder posted:It doesn't actually fit your requirements, but if it has anything to do with showing a chart on a web page, you should probably look at Google Charts. The caveat is that it does require the user have some access to the Internet, so it breaks if they're in, say, a closed off datacenter. That's what I used for the proof of concept. Google Charts are pretty neat, but it seems a bit limited in what you can do. Plus passing everything into the URL is a bit of a pain. Fly posted:We've been using http://jcharts.sourceforge.net/ for nearly a decade. It seems to work quite well. I saw that one but I wasn't really impressed with their samples. They look so...Excel 97. I've been playing around some more with JFreeChart. The amount of customization you can do seems to be very thorough. I think this might be the right engine. JFreeChart + data URI scheme = fletcher fucked around with this message at 00:04 on Feb 13, 2010 |
|
# ¿ Feb 13, 2010 00:01 |
Coredump posted:I thought I was using Arraylist. The idea is I want to make a loop where I feed in a number and it spits out the number of arraylist for me. The program I'm working on is supposed to let someone enter in a bunch of names and specify a number of groups. Then the program is supposed to randomly take the names from the big list and stick them evenly into the number of list the user specifies. The idea is this program will be used in a situation where a teacher needs to split up everyone in class into even random groups. Why do you need more than 1 ArrayList for this? Load all the names in a single ArrayList. Use Collections.shuffle to randomize the order. Then just loop through it and after x names, increase the group #.
|
|
# ¿ Feb 15, 2010 07:40 |
Fly posted:I'll check out JFreeChart when it comes time to redo our current charts. I ended up buying the JFreeChart developer guide. They really put a lot of work into it, and you can do pretty much whatever you want with the charts. I'm really liking using it so far.
|
|
# ¿ Feb 19, 2010 00:37 |
I'm trying to log some database queries that are generated using a custom class, QueryBuilder. I want to log some information about the user logged into my app executing the query as well as how long the query took etc. Essentially I'm doing this: code:
edit: How about adding a getResultSet() to my QueryBuilder class? Is there a way to automatically have it call resultSet.close() and statement.close() when the QueryBuilder gets garbage collected? Do I even need to do that? fletcher fucked around with this message at 20:27 on Feb 19, 2010 |
|
# ¿ Feb 19, 2010 20:11 |
I'm looking at different ways of making objects persistent in Java. I'm not sure if I want to go the RDBMS route and just use MySQL again and write my on SQL. JDO sounds interesting but I think MemcacheDB might be the way to go. What do you guys think? The idea of not having to write any SQL sounds nice, but I feel like I will run into limitations down the road.
|
|
# ¿ Feb 25, 2010 22:26 |
Why does this work fine the first time, but subsequent calls give me the "you must be a registered user to view this page..."code:
|
|
# ¿ Mar 15, 2010 20:07 |
fletcher posted:Why does this work fine the first time, but subsequent calls give me the "you must be a registered user to view this page..." Bump! This is driving me nuts!
|
|
# ¿ Mar 16, 2010 21:29 |
I am in posted:I looked at the cookie that is sent with Firebug. These keys have values: sessionid, __utma, aduserid, bbuserid, bbpassword and sessionhash. I was doing it before in PHP with just the bbuserid and bbpassword so I don't think that's the issue. I'm trying to do this on Google App Engine now. fletcher fucked around with this message at 00:11 on Mar 17, 2010 |
|
# ¿ Mar 16, 2010 23:45 |
|
|
# ¿ May 4, 2024 20:37 |
Is there a way to check and see if anything has been written to a HttpServletResponse?
|
|
# ¿ Mar 26, 2010 08:59 |