Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How to use it and an example with that please. Thanks! If you could also, I want a program that prints an array. I can't do it beaucause it makes me an error, and I want to know if I do something wrong.
Is that code right??
import java.util.Arrays;
kk
I get this:
I
I
[[I#e53108, [I#f62373]I
I
[[I#e53108, [I#f62373]
Osama, when I run your code, there pop ups an error box which says java exception and prints many errors.
Osama, your code when I run it says java Exception in an error box
I get this: I I [[I#e53108, [I#f62373]I I [[I#e53108, [I#f62373]
This is because you are printing a multi-dimensional array. For this, you can use Arrays#deepToString():
System.out.print(Arrays.deepToString(a));
A simple program to print an Array of string values
public class PrintArray{
public static void main(String[] args){
String[] array = {"a","b","c","d"};
for(String s : array)
System.out.println(s);
}
}
the output:-
a
b
c
d
I hope it's useful for you.
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 am new to android and i just want to create a dj player. but for that the starting step is mixing two files. The rough code for that i found on the following link but in that i did not understand how to code for buildShortArray(music1).
I already tried this code but got stuck in the above mentioned method's code.
thank you in advance for help.
Docs here:Mix two files audio wav on android use short array
The code from the link does not show the buildShortArray method.
You need to transform List<Short> into array short[]:
List<Short> music1 = ...;
short[] arrayMusic1 = buildShortArray(music1);
You could write the method buildShortArray like this:
public short[] buildShortArray(List<Short> list) {
short[] array = new short[list.size()];
for(int i = 0; i < list.size(); i++) {
array[i] = list.get(i);
}
return array;
}
However, i'd like to warn you, copy-pasting code is never a good idea.
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 have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof
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
All I need to know is how to find the length of the string inside of the array. I also would like to know how to find which string comes first in alphabetical order in the array.
myArr[0].length()
This will access the string at location 0, then get the length of it.
Also, for sorting alphabetically, you can use
Arrays.sort(myArr);
You can simply use .length method on any string array element to get its length,
And to sort that array alphabetically you ca use .sort method -
For example -
String[] strings = { "Hello ", "This ", "is", "Sorting", "Example" };
Arrays.sort(strings);
So after sorting strings[0] would be Example and string[0].length() would be 7
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 new to java need help
the main string i have is
eg.
"String1/string2/string3/string4/all_free.sdx"
"file1/file2/string3/string4/all_free.sdx"
the end result i need is to be able to isolate and get string3
i can indexof but not able to achieve it in few steps need brainy people help as i am new to JAVA
If you know it's the third item that you want to get, one simple approach could be using split method, like this:
String myString = "String1/string2/string3/string4/all_free.sdx";
String string3 = myString.split("/")[2];
The call of split("/") produces an array of strings like this:
{"String1", "string2", "string3", "string4", "all_free.sdx"}
Now you can apply the subscript operator to grab the element that you want.
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
Basically, I have to write a method that determines whether all the characters in a string are the same, using only library String methods.
Use matches. Please read up the documentation of Pattern class to understand how to use matches function to check your input. It is quite useless for me to give you a straight answer, since you don't learn much from it.
That method will give you one-liner solution after you have understood regex.
public static void main(String[] args) {
String str = "aaaaa";
int count = str.length() - str.replaceAll(String.valueOf(str.charAt(0)), "").length();
if(count == str.length())
System.out.println("All characters in a given String are same");
}
Try this : This is the simplest and best solution for this kind of problem.
One way to solve this is without looping or recursion is by [ab]using String.replace1.
The actual implementation is left as an exercise.
1 It does not require that your code loops, but something must loop.