how to nest if statements in HashSet? [duplicate] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to find the lentgh of a set from a preference.
I tired set.length, but it doesnt work. Anyone know another way to find a length of a set?
set = prefs.getStringSet("key", null);
int X = set.length; //it doesn't like length....

I believe instead of set.length, you'll want to call set.size()

Your set is a Set<String>, not a String[]. So you have to call:
int x = set.size();

Related

How to declare an imageIcon array? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am somewhat new to Java, so excuse this really dumb question. I was just wondering, how does one declare a 2D array of ImageIcons?
Say like this:
ImageIcon[][] arr = new ImageIcon[10][5];
Note that after this line, the array elements will be uninitialized (they will be all equal to null).
If you want to initialize them, you need to loop through your array and call some of the ImageIcon constructors e.g.
arr[i][j] = new ImageIcon();

replace x, y in arraylist of arraylists in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to figure out how to replace a specific index in a arraylist of arraylists
The only stuff I've been able to find so far is how to just get the index with .get(x).get(y)
I'm having no real luck with google at the moment, so I figured I'd finally make a post about it. Any help would be great, thanks in advance.
You can do
.get(x).set(y, value);
Something like this:
ArrayList<ArrayList<String>> s = . . .;
s.get(3).set(4, "new value");
As #peeskillet suggest a best solution..
But check this core java code if it have some sense.
String arrayList[] = {....your array content...};
for (String token : arrayList) {
token = token.replace("x", "replaceanythings");
token = token.replace("y", "replaceanythings");
}

Converting a float to the integer with the same bit representation as it, in java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I think this is not hard in C with pointers. However, how would one do this in java? EG a float is represented as 101001, and you want the integer represented by 101001 (obviously shortened since they're really 32 bits)? Just curious.
I think you want Float.floatToIntBits().

Whitespace matching regex in Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am currently trying to make use of the java string function someString.replaceAll() to find commonly used words (and, the, by, of, etc) and replace them with " ". Based on the answers to the question at Whitespace Matching Regex - Java, I produced this function call:
data.replaceAll("(?i)\\sthe\\s", " ")
However, it isnt working and I'm really not sure why. Nothing about it looks wrong based on what I've found. Please help me!
Strings are immutable!
data = data.replaceAll("(?i)\\sthe\\s", " ");

Is it possible to use a String as the arguments for Files.move(source,target..) in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can you use strings in some way to define the source and target of files.move.
Heres the documentation http://docs.oracle.com/javase/tutorial/essential/io/move.html
According to the javadoc, you can not use strings as arguments for Files.move .
What seems to be a better solution for you, is using the rename method on File. Something like this:
File file = new File("/path/to/file/to/be/moved");
boolean moved = file.renameTo("/new/path/for/the/file");
if(!moved)
//Handle the error
Short answer is no: Files.move requires Path objects. That said, you can use Paths.get(str) to simply turn a String into a Path.

Categories

Resources