Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Separate a big junk of text from main?

  1. #1
    Junior Member
    Join Date
    Nov 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Separate a big junk of text from main?

    Hello,
    I try to explain it quick and dirty.
    I have a programm where I need to put down a lot of text and save it. (fixed/static). <- it will never change.
    I need like 12 components of text, each consisting of like 10 to 40 words.
    I need to save them somewow as an array of string. (dont care what, whats best to save?)
    And then I get from the main programm a few numbers. (doesnt matter how, it will just save some numbers, maybe I type them in).
    Depending on the number it should print out the text on the index from that number.

    Example:
    main says numbers 1,2,3
    it should put out Array[1] + Array[2] + Array[3]
    when the numbers are 0,1
    it should put out the text from Array[0] + Array[1]

    How do I separate this and write it in a hidden separate file, which normaly only classes have?!

  2. #2
    Member
    Join Date
    Jun 2022
    Posts
    41
    Thanks
    1
    Thanked 3 Times in 2 Posts

    Default Re: Separate a big junk of text from main?

    12x40 = 480 words. Since they've been declared as constant, just make them constants.

    Constants.java
    public class Constants {
     
      public static String[] MY_PHRASES = {
        "first phrase",
        "second set of words",
        "third set"
      };
     
    } // Constants

    Usage in main
    public class Scratchpad {
      public static void main(String[] args) {
     
        System.out.println( Constants.MY_PHRASES[2] + " " + Constants.MY_PHRASES[0] );
     
      } // main
    } // Scratchpad
    Last edited by AngleWyrm; November 9th, 2022 at 09:26 AM.

Similar Threads

  1. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  2. Replies: 5
    Last Post: October 18th, 2012, 01:43 PM
  3. separate strings
    By ridg18 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 21st, 2011, 06:22 AM
  4. Junk values
    By abhilash.naik in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: September 9th, 2010, 06:25 AM
  5. How to eliminate Junk charaters from the file...
    By Harry_ in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 10th, 2009, 10:52 AM

Tags for this Thread