Hello,
I've got a Problem with ArrayList. I need it to store a result. Because I want to start with element n I tryed to give the ArrayList a capacity with ensureCapacity(n+1) to use set(n,x) but I get an IndexOutOfBoundsException.
I tryed to store n add(x) before the use of set and this works.
So I'd like to know why it doesn't work on my way and how to solve this because put n times a add(x) isn't a good style ;-)
Best regards,
Sebastian
I've a few lines of code within a project, that I can't see the value of...
buffer[i] = (currentByte & 0x7F) | (currentByte & 0x80);
It reads the filebuffer from a file, stored as bytes, and then transfers then to buffer[i] as shown, but I can't understand what the overall purpose is, any ideas?
Thanks
Hi,
We have this software which loads various bits of data from files that are written using XMLEncode (serialization using XML). We want to migrate from that to our own proprietary file format (can be XML based). Is there a automated way to achieve this initial conversion, without having to perform a deserialization, and then write those objects out in the new format?
XMLEncode format --> New proprietary file format
Thanks!
If i have a class called Dice which contains this method:
public void roll ()
{
this.x = randNum(1, this.sum.length) ;
this.sum[x] ++ ;
}
And i am in a diferent class how do i invoke this method?
I am currently trying InstanceOfObjectName.Dice.roll and its not working. What should i do?
I want to build an notepad-style application on android that will have syntax highlighting. But when I search around the web, I find the syntax highlighting can be done only through use of an awt class. How could I syntax highlight in maybe a custom EditText or TextView view? I know that the release of a syntax highlighter is sort of anticipated, so I want to add my syntax highlighter on the market.
I've got a HashSet with a bunch of (you guessed it) integers in it. I want to turn it into an array, but calling
hashset.toArray();
returns an array of Object type. This is fine, but is there a better way to cast it to an array of int, other than iterating through every element manually? A method I want to pass it to
void doSomething(int[] arr)
Won't accept the Object[] array, even if I try casting it like
doSomething((int[]) hashSet.toArray());
Hi.
I have seen different questions regarding this, but I still find this topic to be very confusing.
All I want to do, is have an abstract class that implements an interface, and have a class extending this abstract class so that the hard class needs to implement getKommune() and setKommune(Kommune kommune), but not the other method, because that is in the abstract class.
I have the following interface.
public interface KommuneFilter {
<E extends AbstractKommune<?>> void addKommuneFromCurrentUser(E e);
Kommune getKommune();
void setKommune(Kommune kommune);
}
And this Abstract class
public abstract class AbstractKommune<E extends AbstractKommune<?>> implements KommuneFilter {
@PrePersist
void addKommuneFromCurrentUser(E e) {
}
}
And I want to use it like this
public class Person extends AbstractKommune<Person> {
private Kommune kommune;
public void setKommune(Kommune kommune) {this.kommune=kommune;}
public Kommune getKommune() {return kommune;}
}
However, I get Name clash: The method of has the same erasure of type but does not override it
Why isn't it correctly overriden?
Hi people. I have a question about type casting. I have the following json String:
{"server":"clients","method":"whoIs","arguments":["hello"]}
I am parsing it to the following Map< String, Object
{arguments=[hello], method=whoIs, server=clients}
It is now possible to do the following:
request.get("arguments");
This works fine. But i need to get the array the is stored in the arguments. How can i accomplish this? I tried (for example) the following:
System.out.println(request.get("arguments")[0]);
But of course this doesn't work..
Does anybody know how this would be possible?
How can you track the movement of a JFrame itself? I'd like to register a listener that would be called back every single time JFrame.getLocation() is going to return a new value.
Here's a skeleton that compiles and runs, what kind of listener should I add so that I can track every JFrame movement on screen?
import javax.swing.*;
public class SO {
public static void main( String[] args ) throws Exception {
SwingUtilities.invokeAndWait( new Runnable() {
public void run() {
final JFrame jf = new JFrame();
final JPanel jp = new JPanel();
final JLabel jl = new JLabel();
updateText( jf, jl );
jp.add( jl );
jf.add( jp );
jf.pack();
jf.setVisible( true );
}
} );
}
private static void updateText( final JFrame jf, final JLabel jl ) {
jl.setText( "JFrame is located at: " + jf.getLocation() );
jl.repaint();
}
}
I need to find when finalized method called in the JVM. I Created a test Class which write into file when finalized method called by Overriding the protected finalize method It is not executing. Can anybody tell me the reason why it is not executing?? Thanks in Advance
I want to create an XY array of integers (or whatever type), but I want to use methods like "add", "remove", "contains", "indexOf" similar to ArrayList class.
Is there any existing class with these capabilities?
PS: I don't want to create an ArrayList of ArrayList
Hi,
If I have a superclass, say Animal,
and two subclasses: Zebra and Giraffe,
If I decide to define a Vector of Animals:
Vector <Animal> animals = new Vector();
and I want to say: You can add Giraffes, but you must own at least one Zebra first.
What is the best way to do this without using RTTI? (instanceof)
I want to create an XY array of integers (or whatever type), but I want to use methods like "add", "remove", "contains", "indexOf" similar to ArrayList class.
Is there any existing class with these capabilities?
PS: I don't want to create an ArrayList of ArrayList
Hello everyone.
I want to implement a RSA algorithm to encrypt an image (byte[]). To generate my two keys I used this piece of code :
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
keygen.initialize(512);
keyPair = keygen.generateKeyPair();
Once public and private key are generated, I would like to show them to the user so he can distribute the public key and use the private key to decode. How can I get back those key?
Using keygen.getPrivateKey() and keygen.getPublicKey() give me all the information of the RSA algorithm, not only the keys I need.
Thanks
Hi,
I would like to get all combination of a number without any repetation.
Like 0.1.2, 0.2.1, 1.2.0, 1.0.2, 2.0.1, 2.1.0.
I tried to find an easy scheme but couldn't find so I drawed a graph/tree for it and this screams to use recursion.
But I would like to do it without, if this is possible.
So could anyone please help me how to do that?
Thank you in advance,
Andreas
Let's say I had:
protected void performLogic(List<Object> docs) {
...
}
In the code where I'm going to be calling this method, I have a List<String> list. I want to call performLogic, passing this list. But it won't work because the lists are 2 different types:
public void execute() {
List<String> docs = new ArrayList<String>();
performLogin(docs); // won't work
}
I tried casting to List<Object> also, but that won't work either.
So is the only way to do this is to make a new ArrayList of Object and just add the values and then pass it? Just seems cumbersome. I wondered if there was a better way to do it.
Thanks.
I would like to refactor code which looks something like this:
String input; // input from client socket.
if (input.equals(x) {
doX();
} else if (input.equals(y) {
doY();
} else {
unknown_command();
}
It is code which checks input from socket to perform some action, but I don't like the if else construction because every time a new command is added to the server (code) a new if else has to be added which is ugly. Also when deleting a command the if else has to be modified.
I am working on a on-screen keyboard for Android, and I need to recognize starting points, turning points and end points of lines drawn by the user on the keyboard. A simple straightening function would be nice, as it is difficult to draw a perfectly straight line even with a stylus, not to mention finger-only touchscreens today.
What I am trying to write is something like Swype.
Any good libraries that I can use or make reference to?
Given:
class A
{
public void m(List l) { ... }
}
Let's say I want to invoke method m with reflection, passing an ArrayList as the parameter to m:
List myList = new ArrayList();
A a = new A();
Method method = A.class.getMethod("m", new Class[] { myList.getClass() });
method.invoke(a, Object[] { myList });
The getMethod on line 3 will throw NoSuchMethodException because the runtime type of myList is ArrayList, not List.
Is there a good generic way around this that doesn't require knowledge of class A's parameter types?
Hello,
i have a string %/O^/O%/O. I want to find the last / to split the string. First attemp was: \/[POL]$ but that gets it inclusive the "O" which is obvious. Has somebody a tip?
I have a JPanel that encapsulates two JPanels, one on top of the other.
The first holds two JLabels which hold the playing cards.
The second holds the player's text (name and score).
However, when I remove the player's cards, the lower JPanel moves up to the top, which i would prefer that it not do. Is there a way to keep it in place regardless of whether the top JPanel is occupied or not?
Thanks