I am trying to write a program to order a list of strings by most least frequent characters within the list. For example, if the list was [apple, orange, banana] the letter frequency within the list would be a – 5, n – 3, p – 2, e – 2, l- 1, o – 1, r – 1, g –
Tag: string
Substring not equal to the string of the first character
I am struggling to figure out what’s wrong with my code. When the user input is “apple” I get that it doesn’t begin with a vowel. Answer You made a mistake using the substring method, you should say the start position in first parameter and the end position in second parameter : And now it works fine 🙂 :
String anagram in Java
i am trying to create a program for string anagram that follows these conditions: method should allow only letters, white space, commas and dots in an anagram. If there are any other characters, then the string cannot contain an anagram. The method should ignore all white space, commas and dots when it checks the text. If there are no letters
Java Bubble Sort String ArrayList Object
Can someone find why this isn’t being sorted I can’t seem to find what I have wrong? The output that is being displayed is how I input them after each other thus the sort method isn’t working… Answer There are three errors: 1. It does i++ instead of i+1. i++ means: return i then increment its value. So t1 and
How to insert a string in a circular linked list (i want to check the duplicate words in the circular linked list)?
Here is the linked class that I created and I wrote a method that checked if there was a duplicate words in my linked list. I tried to sent the string to the addFirst method but I don’t know why it doesn’t work with me in the main i can’t insert the words to the circular linked list Answer sorry
Given 2 strings, remove only one digit to make 1 string lexicographically smaller
I am trying to work through a coding problem of string manipulation in Java. The question is that Given two strings S and T consisting of digits and lowercase letters, you are allowed to remove only one digit from either string, count how many ways of removal to make S lexicographically smaller than T. I came up with this test
How to return all array permutations iteratively into a two-dimensional array?
I am trying to write a program that will iterate through all possible permutations of a String array, and return a two dimensional array with all the permutations. Specifically, I am trying to use a String array of length 4 to return a 2D array with 24 rows and 4 columns. I have only found ways to print the Strings
Cannot invoke charAt(int) on the array type String[]
I’m doing a function that counts digits in a string: The error is: Any ideas how to fix that? Answer You are trying to invoke the charAt() method on a String[]. String[] does not have such a method, but String does. What I believe you wanted to do is: This will get the char at position i in the String
Java-Merging two strings using alternating characters while also preserving runs
Merges two strings together, using alternating characters from each, except that runs of the same character are kept together. For example, (“abcde”, “xyz”) returns “axbyczde” (“abbcde”, “xxxyzzzz”) returns “axxxbbyczzzzde” Given the code below, the output I get is “axbxbcydzezzzz” Not only does this fail to preserve the runs, but it also adds and removes some characters. Some help as to
How to use strings on java (Android)
I’m working on a project where I’ve defined several strings to use on my project. I want to use a string to be displayed as my subtitle of the page on the toolbar. The reason I’m using strings is because I want my app to be translation supported. Here is how I use subtitles on the toolbar of my activity: