Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java array gap type question, i'm really stuck

 
salpie Nowinski
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,

so i have this array that is made of 31 classes (i don't even know if you can do that) and each class has 2 strings and 1 integer, but with each of the 31 classes one of each of those strings i want to have a gap in the middle. so here's an example of one class:

so the string i want to have a gap of three characters is: "$TTACCT$3$TGAACT$" so i thought i should use the symbol "$" i guess as a delimiter so i could split it up so there would be a gap, but i'm not sure what i need to say in order for that to happen. sorry if this is very confusing, i am very very new to java. i would really appreciate any help at all. thanks
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you want to have an array of 31 objects where each object is an instance of a different class? That is only possible if each of those classes inherit from the same class, in which case the array must be of the inhered class type.
For example an array can contain cats and dogs if the array is of type Animal.

Regarding your question about splitting the string, you can use the String method split() for that or iterate through the string cutting one chunk at a time using substring() and indexOf(). You can about String methods here
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unnar Björnsson wrote:. . . That is only possible if each of those classes inherit from the same class, in which case the array must be of the inhered class type. . . .
You could always use an Object[], but what is the point of an array of many objects of different classes?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic