First of all,I am newbie in Java and I came across this issue several times. I am trying to return the number of occurrences of a char in a string and I implemented a method called countcharacters which looks like this:
public static int[] countcharacters(String s)
{
String alphabet="abcdefghijklmnopqrstuvwxyz";
int[] sircounter=new int[alphabet.length()];
for(int i=0;i<sircounter.length;i++)
{
sircounter[i]=0;
}
for(int j=0;j<alphabet.length();j++)
{
for(int i=0;i<s.length();i++)
{
if(alphabet.charAt(j)==(s.charAt(i)))
{
sircounter[j]++;
}
}
}
return sircounter;
}
In other words, each time a character from alphabet is found in my string ,the argument of the method, the value zero from each position from sircounter is incremented with the number of occurrence. I wanted to print the array position by position but it didn't work and if I do something like this in the main method:
String text="hannah";
System.out.println(Class.countcharacters(text));
I get a hex code: [I@659e0bfd which I don't understand. Could you help me? Many thanks and have a nice day!