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");
}
Related
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();
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 want to detect the file structure in a string.
e.g
if I have a string as /name/test/testme/2 I should be able to store it in a arraylist as different elements like {[name],[test],[testme],[2]}
String[] elements = "/name/test/testme/2".split("/");
More info can be found in the String.split() Javadoc
As Lukas pointed out, (please give him some upvoting) you should use the split method.
String[] elements = "/name/test/testme/2".split("/");
The regular expressions are not used to split strings in sections. Regular expressions are used for matching the target string with a specific generic format. In this case a boolean value indicating if the strings match is returned.
Hope I helped!
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
In my JSON response i am getting date like this [1987,8,22], but I have to display the date like 22-08-1987. Can anyone tell me how to convert this.
Thanks in advance.
Use the org.json package to parse the JSON into a JSONArray (if your haven't already done so). Then you can instantiate a GregorianCalendar using the three elements of the array accessible through JSONArray.getInt. This date then can be formatted as any other Java date object.
You can try this::
String date = "1987,8,22";
String[] part = date.split(",");
date = part[2]+"-"+part[1]+"-"+part[0];
Hope it Helps!!
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", " ");
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.