0

I have some problems about char[] method. I am working on some code block in java. And i need to use Turkish characters in my program. But originally codes in russian languages.

Here original codes

                TableRow row = null;
                int w = 0;
                for (char q = 'A'; q <= 'Я'; q++)
                {
                    if (w++ % columns == 0) {
                        row = new TableRow(AlphabetActivity.this);
                        addView(row);
                    }
                    final Button button = new Button(AlphabetActivity.this);
                    button.setBackgroundResource(R.drawable.selector_dashboard_button);
                    button.setText("" + q);
                    button.setTag(q);

with this codes i've got this results https://i.stack.imgur.com/AqUCO.jpg

When i change this part like this

for (char q = 'a'; q <= 'z'; q++)

i am getting this results https://i.stack.imgur.com/dZcZN.jpg

When i change like this (this time i write "A" with keybord(manually) i mean not original "A")

for (char q = 'A'; q <= 'Я'; q++)

I've got this https://i.stack.imgur.com/9a6ni.jpg

I really didn't understand what i am deal with. And if i use this(first codes)

for (char q = 'a'; q <= 'z'; q++)

and deleted this

int w = 0;
if (w++ % columns == 0)

I've got all latin alphabet like this https://imgur.com/7NdP0kU

But i need Turkish characters.

I tried some solutions that i saw on stackoverflow like these

char[] q ={ 'a', 'b', 'ç', 'd', 'e' };
char[] q = "abcdefghijklmnopqrstuvwxyz".toCharArray();

And many more, but when i try these codes i getting this https://i.stack.imgur.com/W4Jei.jpg

So is there any expert to help me?

ibo toci
  • 23
  • 1
  • 8
  • Instead of printing the `char[]` directly, try using `String.valueOf(q)`. Your last results show the hash code of the `char[]` instead of the `String` value that array would represent. – Vince May 25 '19 at 00:53
  • Possible duplicate of [How do I print my Java object without getting "SomeType@2f92e0f4"?](https://stackoverflow.com/questions/29140402/how-do-i-print-my-java-object-without-getting-sometype2f92e0f4) – Vince May 25 '19 at 00:55

1 Answers1

0

I really didn't understand what i am deal with.

The original source character displayed to you as A is undoubtedly Unicode character U+0410, "CYRILLIC CAPITAL LETTER A", as opposed to U+0041, "LATIN CAPITAL LETTER A". The latter is the one you produce with the shifted 'A' key on a US or Western European keyboard. You could verify this by printing out the numeric value of the character in question.

when i try these codes i getting this [garbage]

That's a totally different issue: you're printing the string value of the array (as obtained via q.toString()), which is not the same thing as a String containing the array's characters (String.valueOf(q)).

As long as you use the character encoding expected by the compiler when you save the file (probably UTF-8), and that encoding supports the characters you want (UTF-8 supports all Unicode characters), you should be able to write them into your source literally, and print them out successfully.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157