Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java array gap type question, i'm really stuck

 
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
 
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
 
Marshal
Posts: 70370
283
  • 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?
 
I've never won anything before. Not even a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic