Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:30:23+00:00 2026-06-14T05:30:23+00:00

Basically I want to create a data structure of values already known at compile

  • 0

Basically I want to create a data structure of values already known at compile time. In C I’d do it like this:

struct linetype { int id; char *descr; };

static struct linetype mylist[] = {
    { 1, "first" },
    { 2, "second" }
};

The only soultion I have found in Java involves creating the array at runtime:

public class Outer {

    public class LineType {
        int id;
        String descr;

        private LineType( int a, String b) {
          this.id = a;
          this.descr = b;
        }
    }

    LineType[] myList = { 
        new LineType( 1, "first" ),
        new LineType( 2, "second" ),
    };

This appears cumbersome and ineffective (when the structures get long and complex). Is there another way?

(NB: please disregard any syntax errors as this is only sample code created for this question. Also, I am aware a String is somethign else than a character pointer pointing into the data segment. However, the argument works with primitive data types as well).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:30:24+00:00Added an answer on June 14, 2026 at 5:30 am

    You have to make LineType a static class:

    public class Outer {
    
        public static class LineType {
            int id;
            String descr;
    
            private LineType( int a, String b) {
              this.id = a;
              this.descr = b;
            }
        }
    
        static LineType[] myList = { 
            new LineType( 1, "first" ),
            new LineType( 2, "second" ),
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to create one large object of many object in JavaScript. Something
So basically I want to create a GUI app using PySide and the Qt
I have php generating html and I want to create layers. Basically I want
I want to create own filetype to save objects in my app. Basically, I
I want to create a Google Docs document from within Haskell, so basically I
How to create imaged scrollbars, for example: http://www.openstudio.fr/jquery/index.htm Basically, I want to create my
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
Having issue with prefetching data and displaying on uitableview. So basically I want to
Basically I want to create a custom handler to unserialize a db field called
I have a data frame with several rows and I want to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.