Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am not sure how to shuffle a char array using Java so could anyone
help me, but please keep it really simple because I'm at GCSE level right now, Thank you.
Try using Collections.shuffle method like:
Character[] myarray = ...
List<Character> charList = Arrays.asList(myarray);
Collections.shuffle(charList);
Character[] myShuffledArray = (Character[]) charList.toArray();
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to find the specific word in the text file and store that word in the array of list.
I do not how it can be achieved or approached.
A basic solution:
public ArrayList getWords(String searchWord, String listOfWords){
ArrayList<String> foundWords = new ArrayList<>();
if (listOfWords.contains(searchWord)){
foundWords.add(searchWord);
}
return foundWords;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Can anyone help me to write code that find how many characters string has.
All you need is - int len = yourString.length();
StringUtils should provide you with something that you are looking for:
int count = StringUtils.countMatches("haahaahaa", "a");
System.out.println(count);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have
String[] country={"USA","ks a","UK","France"};
I have a variable String z.
I want to say
if(z.equals(any element of my array (USA or ks or France)
but randomly:
if(z.equals(country[i]){
Doing action any code
}
Can anybody help me?
you can use
if ( Arrays.asList(country).contains(z)) {
// your code
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using Java to implement the Apriori algorithm but one problem exists.
ArrayList<String> l1=new ArrayList<>();//L1
...
ArrayList<String[]> lk1=l1;//Lk-1
Then it warns that: cannot convert from ArrayList<String> to ArrayList<String[]>. How can I solve this problem?
They're different types. Ignore the collection and just look at the underlying type.
String str = "This is a string.";
String[] array = str;
These are two different types, unconvertable, so as T for the collection, the collections are then unconvertable. Very basic concept here.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to define specific numbers out of an array of 52 numbers so I can assign them an image (yes I am creating an applet). I don't think that code is necessary for any of you to answer this question. Any help would be fantastic.
I'm not sure I understand what you're asking. You can set an item in an array this way:
myArray[4] = 52;
That would set array index #4 (remember it's zero based so it's actually the 5th item) to the value of 52. Is that what you're looking for?