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 5 of 5

Thread: Implementing HTML tags in Java Source Code

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Implementing HTML tags in Java Source Code

    On finding a '{' in the ArrayList<String> a, I want my code to insert a line break in the next index position. How do I insert the line break using HTML tags? I know HTML line break is represented by <br> but is this compatible with a java source code...? Many thanks.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: Implementing HTML tags in Java Source Code

    If I understand your question correctly (posting code would help describe your scenario), suppose you have:
    ArrayList<String> list = new ArrayList<String>();
    list.add("<html>");
    list.add("{");
    list.add("}");
    Then iterate through and add the br string where you wish:
    for ( int i = list.size()-1; i >= 0; i-- ){
        if ( list.get(i).equals("{")){
            list.add( i+1, "<br>");
        }
    }
    Note the loop is in reverse, so you can add elements without disrupting the future portions of the arraylist

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Implementing HTML tags in Java Source Code

    Here's my piece of code:
     public void studyText(String originalText) {
     
            textInArray = toArray(originalText);
            Iterator arrayText = textInArray.iterator();
     
            while (arrayText.hasNext()) {
                if (arrayText.next().equals('{') || arrayText.next().equals('}')){
                    int i = textInArray.indexOf(arrayText.next()); 
                    textInArray.add(i+1, "<br>"); 
                }
            }
    >where toArray() is a method within the same class!

    Thank you, you've answered my question! I wasn't too sure how to incorporate the HTML tags into my code!
    (Didn't try running this piece of code yet, NetBeans doesn't seem to have any syntactic problem with it but if you see any logic flaw...let me know. Many thanks!)
    Last edited by helloworld922; March 20th, 2010 at 01:11 PM.

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Implementing HTML tags in Java Source Code

    Oh and do I have to insert <html> in the first position of the ArrayList?

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: Implementing HTML tags in Java Source Code

    Quote Originally Posted by bookface View Post
    Oh and do I have to insert <html> in the first position of the ArrayList?
    I don't know how you wish to use your ArrayList, why you are using a List, or what you fully want to accomplish in the scheme of things - so I couldn't advise you one way or the other.

    In the code you posted, a note of caution in changing a collection while iterating over its iterator. Glad I could answer your question - the reverse loop will allow you to change the list as you loop through and not face the hazards of changing the collection while using its iterator.

Similar Threads

  1. Source code for Email address book/contacts importer
    By jega004 in forum Java Theory & Questions
    Replies: 4
    Last Post: November 23rd, 2012, 11:49 AM
  2. How to Grab the HTML source code of a website URL index page?
    By JavaPF in forum Java Networking Tutorials
    Replies: 6
    Last Post: April 22nd, 2010, 02:46 PM
  3. Related to Html and Java Script?
    By JackyRock in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: February 17th, 2010, 02:10 AM
  4. Help with html tags in java
    By peliukasss in forum Member Introductions
    Replies: 0
    Last Post: February 2nd, 2010, 05:47 AM
  5. How can i add a new count to this source code ?
    By mm2236 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 30th, 2010, 09:21 PM