Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaLanguage
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Arrays== Array enthalten entweder: *basic types *object references *array references. Für alle Typen wird bei der Konstruktion der Defaultwert des Datentyps (null bei objects) eingesetzt. Arrays are declared by int[] Array1; int Array[]; and constructed by int[] Array1; Array1 = new int[x]; int[] Array2 = new int[n]; char[] Array3 = {'\u0031','\u0033'}; int[] primes; primes = new int[]{ 2, 5, 7, 11, 13 }; wobei n vom basic type byte, short oder int sein muß - long geht nicht. Arrays have the standard property length which can be used through if (Array2.length > 1) { ... } int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println("Count is: " + item); } Creating an array of objects only allocates storage for object references, not the object themselves. Elements are initialized to their default value which is 0, 0.0, false or null. If you pass an array to an method you would declare the method like this <return type> <method name>'''('''<type>[(<Space>)*]'''[]'''[(<Space>)*]<parameter name>''')''' In this case you don’t have to call new. Another initialization is <Method>'''( new''' <Type>'''[] {''' <Element1>''',''' ...''',''' <ElementN> '''} );''' An java array remembers the type of elements. Java arrays are '''0-based'''. Arrays can be cast to Object and Clonable, but not to String. Die Klasse '''java.util.Arrays''' definiert nützliche Funktionen im Umgang mit Arrays. If an array is created you cannot change its size. If you need to change the size at runtime and you only want to store subclasses of object you should use the class vector. Der Nachteil von vectors ist, dass es kein typisierter Speicher ist sondern alle Objekt-Subclasses speichert. Dies führt leicht zu Fehlern. Beim Auslesen aus einem vector muss man immer casten.
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width