Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm coding in Java and I want to split my string. I want to split it at. /* sort */ Yes I plan to split

I'm coding in Java and I want to split my string. I want to split it at.

/* sort */ 

Yes I plan to split a .java file that I have read as a string so I need it to include "/* sort */". I'm creating a code that sorts Arrays that are predefined in java class file.

Exactly that and do another split at

} 

and then I wanted help how to go about splitting up the array since I'll be left with

an example would be this

final static String[] ANIMALS = new String[] /* sort */ { "eland", "antelope", "hippopotamus"}; 

My goal would be to sort that Array inside a .java file and replace it. This is my current code

 private void editFile() throws IOException { //Loads the whole Text or java file into a String try (BufferedReader br = new BufferedReader(new FileReader(fileChoice()))) { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } everything = sb.toString(); } arrayCutOff = everything.split("////* sort *////"); for(int i = 0; i < arrayCutOff.length; i++){ System.out.println(arrayCutOff[i]); } } 

This basically reads the whole .txt or .java file completely with the exact same formatting into one string. I planned to split it at /* sort */ and sort the array inside but I realized if I did that I probably can't replace it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Why do new ventures often turn to consultants for advice?

Answered: 1 week ago

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago